signed distance between plane and point

后端 未结 2 1992
[愿得一人]
[愿得一人] 2020-12-31 18:44

I cannot find a consistent method for finding the signed distance between a point and a plane. How can I calculate this given a plane defined as a point and a normal?

<
相关标签:
2条回答
  • 2020-12-31 19:27

    You're making things much too complicated. If your normal is normalized, you can just do this:

    float dist = dotProduct(p.normal, (vectorSubtract(point, p.point)));
    
    0 讨论(0)
  • 2020-12-31 19:49

    dont worry i understand exactly how you feel. I am assuming you want some code snippets. so you can implement it in your own. you need to do a lot more work than just finding out the dot product.

    It is up to you to understand this algorithm and to implement it into your own program what i will do is give you an implementation of this algorithm

    signed distance between point and plane

    Here are some sample "C++" implementations of these algorithms.

    // Assume that classes are already given for the objects:
    //    Point and Vector with
    //        coordinates {float x, y, z;}
    //        operators for:
    //            Point  = Point ± Vector
    //            Vector = Point - Point
    //            Vector = Scalar * Vector    (scalar product)
    //    Plane with a point and a normal {Point V0; Vector n;}
    //===================================================================
    
    // dot product (3D) which allows vector operations in arguments
    #define dot(u,v)   ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
    #define norm(v)    sqrt(dot(v,v))  // norm = length of vector
    #define d(u,v)     norm(u-v)       // distance = norm of difference
    
    // pbase_Plane(): get base of perpendicular from point to a plane
    //    Input:  P = a 3D point
    //            PL = a plane with point V0 and normal n
    //    Output: *B = base point on PL of perpendicular from P
    //    Return: the distance from P to the plane PL
    float
    pbase_Plane( Point P, Plane PL, Point* B)
    {
        float    sb, sn, sd;
    
        sn = -dot( PL.n, (P - PL.V0));
        sd = dot(PL.n, PL.n);
        sb = sn / sd;
    
        *B = P + sb * PL.n;
        return d(P, *B);
    }
    

    Taken from here: http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104.htm

    PK

    0 讨论(0)
提交回复
热议问题