Check which side of a plane points are on

倖福魔咒の 提交于 2019-11-27 13:42:18

问题


I'm trying to take an array of 3D points and a plane and divide the points up into 2 arrays based on which side of the plane they are on. Before I get to heavily into debugging I wanted to post what I'm planning on doing to make sure my understanding of how to do this will work.

Basically I have the plane with 3 points and I use (pseudo code):

var v1 = new vector(plane.b.x-plane.a.x, plane.b.y-plane.a.y, plane.b.z-plane.a.z);
var v2 = new vector(plane.c.x-plane.a.x, plane.c.y-plane.a.y, plane.c.z-plane.a.z);

I take the cross product of these two vectors to get the normal vector.

Then I loop through my array of points and turn them into vectors and calculate the dot product against the normal.

Then i use the dot product to determine the side that the point is on.

Does this sound like it would work?


回答1:


Let a*x+b*y+c*z+d=0 be the equation determining your plane.

Substitute the [x,y,z] coordinates of a point into the left hand side of the equation (I mean the a*x+b*y+c*z+d) and look at the sign of the result.

The points having the same sign are on the same side of the plane.

Honestly, I did not examine the details of what you wrote. I guess you agree that what I propose is simpler.




回答2:


Your approach sounds good. However, when you say "and turn them into vectors", it might not be good (depending on the meaning of your sentence).

You should "turn your points into vector" by computing the difference in terms of coordinates between the current point and one of the points in the plane (for example, one of the 3 points defining the plane). As you wrote it, it sounds like you might have misunderstood that ; but apart from that, it's ok!




回答3:


Following the 'put points into the plane's equation and check the sign' approach given previously. The equation can be easily obtained using SymPy. I used it to find location of points (saved as numpy arrays) in a list of points.

from sympy import Point3D, Plane
plane=Plane(Point3D(point1), Point3D(point2), Point3D(point3))
for point in pointList:
        if plane.equation(x=point[0], y=point[1],z=point[2]) > 0:
            print "point is on side A"
        else:
            print "point is on side B"

I haven't tested its speed compared to other methods mentioned above but is definitely the easiest method.



来源:https://stackoverflow.com/questions/15688232/check-which-side-of-a-plane-points-are-on

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!