Search code examples
algorithmvector3dconvex

Determining the position of a point in relation to a given 3D surface


I'm trying to implement the Quick hull algorithm for computing the 3D convex hull. The problem is that I need to know if a point can "see" a given surface.

The surface has a direction clockwise or counter clockwise direction.

I wrote a small opengl program to illustrate the algorithm operation graphically.

I tried various equations that I saw other algorithms use (normalized cross product, distance of the dot from the plane)

They all led to the wrong step being taken in the algorithm. Meaning they decided a certain surface was visible from the point(which you could see graphically it isn't)

An example for a surface or a "face".

e1 = 0, 0, 0 to 10, 0, 0
e2 = 10, 0, 0 to 10, 10, 0
e3 = 10, 10, 0 to 0, 10, 0
e4 = 0, 10, 0 to 0, 0, 0

<---------/\
||        ||
||        ||
||        ||
\/--------->

lets say that I have two points and I would like to know which side of the surface they are located on.

p1 = -1, -1, -1 p2 = 1, 1, 1

Any help would be much appreciated.


Solution

  • The first step is to determine the normal of the plane. This can be achieved with the cross product. E.g.:

    normal = cross(e2 - e1, e3 - e1);
    

    Then you need a vector to compare the normal to:

    compare = point - e1
    

    And the dot product of both vectors describe, if both vectors point in the same direction of the normal:

    side = dot(normal, compare)
    

    If side > 0, then the point is on the side of the plane the normal is pointing towards. If it is < 0, it is on the opposite side. If it is = 0, it is exactly on the plane.

    The important step is to define the normal so that it points in the correct description. With only the polygon, you can just define the normal by the order of the corner points. E.g. upper side is the side from which points are clockwise. If you need something different, you have to provide more information.