开发者

Intersection of infinite volumes of any dimension

开发者 https://www.devze.com 2023-03-23 15:02 出处:网络
I need code/text/google keywords/other resources to implement this class. Speed doesn\'t matter. It should just work for any number of dimensions.

I need code/text/google keywords/other resources to implement this class. Speed doesn't matter. It should just work for any number of dimensions.

class InfiniteVolume: # such as a point, line, plane, volume, 4d-volume
    def __init__(self, points):开发者_Python百科 # 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()
        # ???


You're trying to represent an N-dimensional space embedded in an M-dimensional space. For example, (N=2, M=3) is a plane in a 3-dimensional "world".

You can implement a defining set of points if you like, but the natural way to represent such a subspace is with a set of linear equations or basis vectors, so this should be the underlying implementation. If you use basis vectors, there are N of them. If you use equations, each reduces the dimensionality by 1, so there are M-N of them.

To find the intersection of two such subspaces, you just combine their sets and reduce (to a set of linearly independent vectors or equations). The dimensionality of the intersection can be anything from zero to N.

These techniques are straightforward and well-known, and come under the heading of Linear Algebra.

EDIT:
I think it's easiest to deal with the basis vectors.

  1. Use the points to get the basis vectors.
  2. Use the basis vectors to find the basis vectors of the orthogonal space (e.g if the space is a line in 2D, the orthogonal space is a perpendicular line, if the space is a line in 3D, the orthogonal space is a plane perpendicular to the line, if the space is a plane in 3d, the orthogonal space is a line perpendicular to the plane).
  3. If you want, it's trivial to get the equations for the space from the vectors for the orthogonal space.
  4. To get the intersection of two spaces, take the union of their bases and reduce to a basis. Solve for one common point and you're done.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号