How do I get three non-colinear points on a plane? - C++

后端 未结 3 1393
鱼传尺愫
鱼传尺愫 2020-12-30 16:41

I\'m trying to implement at line-plane intersection algorithm. According to Wikipedia I need three non-colinear points on the plane to do that.

I therefore tried imp

3条回答
  •  無奈伤痛
    2020-12-30 17:17

    A plane can be defined with several ways. Typically a point on the plane and a normal vector is used. To get the normal vector from three points (P1, P2, P3 ) take the cross product of the side of the triangle

    P1 = {x1, y1, z1};
    P2 = {x2, y2, z2};
    P3 = {x3, y3, z3};
    
    N = UNIT( CROSS( P2-P1, P3-P1 ) );
    Plane P = { P1, N }
    

    The reverse, to go from a point P1 and normal N to three points, you start from any direction G not along the normal N such that DOT(G,N)!=0. The two orthogonal directions along the plane are then

    //try G={0,0,1} or {0,1,0} or {1,0,0}
    G = {0,0,1};
    if( MAG(CROSS(G,N))

    A line is defined by a point and a direction. Typically two points (Q1, Q2) define the line

    Q1 = {x1, y1, z1};
    Q2 = {x2, y2, z2};
    E = UNIT( Q2-Q1 );
    Line L = { Q1, E }
    

    The intersection of the line and plane are defined by the point on the line r=Q1+t*E that intersects the plane such that DOT(r-P1,N)=0. This is solved for the scalar distance t along the line as

    t = DOT(P1-Q1,N)/DOT(E,N);
    

    and the location as

    r = Q1+(t*E);
    

    NOTE: The DOT() returns the dot-product of two vector, CROSS() the cross-product, and UNIT() the unit vector (with magnitude=1).

    DOT(P,Q) = P[0]*Q[0]+P[1]*Q[1]+P[2]*Q[2];
    CROSS(P,Q) = { P[1]*Q[2]-P[2]*Q[1], P[2]*Q[0]-P[0]*Q[2], P[0]*Q[1]-P[1]*Q[0] };
    UNIT(P) = {P[0]/sqrt(DOT(P,P)), P[1]/sqrt(DOT(P,P)), P[2]/sqrt(DOT(P,P))};
    t*P =  { t*P[0], t*P[1], t*P[2] };
    MAG(P) = sqrt(P[0]*P[0]+P[1]*P[1]+P[2]*P[2]);
    

提交回复
热议问题