u14*_*796 3 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(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()
# ???
Run Code Online (Sandbox Code Playgroud)
您试图表示嵌入在M维空间中的N维空间.例如,(N = 2,M = 3)是三维"世界"中的平面.
如果您愿意,可以实现一组定义的点,但表示这样一个子空间的自然方式是使用一组线性方程或基础向量,因此这应该是底层实现.如果使用基矢量,则有N个.如果使用方程式,则每个方程式将维数减少1,因此存在MN.
要找到两个这样的子空间的交集,您只需将它们的组合并减少(到一组线性独立的向量或方程).交点的维数可以是从零到N的任何值.
这些技术很简单,众所周知,属于线性代数的标题.
编辑:
我认为处理基础向量最容易.