Python 任意维无限体积的交集
我需要代码/文本/谷歌关键词/其他资源来实现这个类。速度不重要。它应该只适用于任意数量的维度Python 任意维无限体积的交集,python,math,intersection,multidimensional-array,Python,Math,Intersection,Multidimensional Array,我需要代码/文本/谷歌关键词/其他资源来实现这个类。速度不重要。它应该只适用于任意数量的维度 class InfiniteVolume: # such as a point, line, plane, volume, 4d-volume def __init__(self, points): # two points for line, three points for plane, etc. self.points = points assert all
class InfiniteVolume: # such as a point, line, plane, volume, 4d-volume
def __init__(self, points): # two points for line, three points for plane, etc.
self.points = points
assert all(len(p)==len(points[0]) for p in points)
def vdim(self): # Dimensions of the volume. For example 2.
return len(self.points)-1
def wdim(self): # Dimensions of the world. For example 3.
return len(self.points[0])
def __contains__(self, point):
# ???
def intersect(self, other):
assert self.wdim() == other.wdim()
# ???
您试图表示嵌入在M维空间中的N维空间。例如,(N=2,M=3)是三维“世界”中的平面 如果愿意,可以实现一组定义的点,但是表示这样一个子空间的自然方式是使用一组线性方程或基向量,因此这应该是基本实现。如果使用基向量,则有N个基向量。如果你使用方程,每一个都会将维数减少1,因此有M-N个方程 要找到两个这样的子空间的交集,您只需将它们的集合合并并减少(到一组线性独立的向量或方程)。交点的维数可以是从零到N的任何值 这些技术都是直截了当和众所周知的,并在标题下 编辑:
我认为处理基向量最简单
你需要计算出给定点的距离。这是一个已知的算法问题,对于飞机来说很简单。但是,如果没有一个额外的变量或两个方程式,就无法定义3D中的线条。另外,我可以计算出一个特殊情况下的方程,但我希望代码能做到这一点。我不知道怎么做。@knizz:是的,在3D中定义一条线是(N=1,M=3),所以它需要M-N=2个方程。你想让代码从这些点推导出方程吗?@这是一个我知道N和M的具体例子。但是代码应该适用于任何N和M。