Raised This Month: $ Target: $400
 0% 

Equation. Straight cutting the plane.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 01-07-2013 , 03:32   Re: Equation. Straight cutting the plane.
Reply With Quote #2

just for more information to sum up all of your said:
you have three vectors of the BOX
and you have X,Y,Z coordinates of point, and you want to know if this point is inside BOX (including border-vectors)?



or you have three vectors of BOX and one other vector, and you want to know if the other vectors have intersection with BOX? but in this case point can be outside too and answer will be true.

PHP Code:
stock intersection_lineplane( const Float:flp][ ], Float:fpp][ ]/*, &Float:d, &Float:t*/ )
{
    new 
Float:vd], Float:pv][ ], Float:nv];
    
    
vd] = flp][ ] - flp][ ];
    
vd] = flp][ ] - flp][ ];
    
vd] = flp][ ] - flp][ ];
    
    
pv][ ] = fpp][ ] - fpp][ ];
    
pv][ ] = fpp][ ] - fpp][ ];
    
pv][ ] = fpp][ ] - fpp][ ];
    
    
pv][ ] = fpp][ ] - fpp][ ];
    
pv][ ] = fpp][ ] - fpp][ ];
    
pv][ ] = fpp][ ] - fpp][ ];
    
    
/* correct */
    
nv] = ( pv][ ] * pv][ ] ) - ( pv][ ] * pv][ ] ); 
    
nv] = -* ( ( pv][ ] * pv][ ] ) - ( pv][ ] * pv][ ] ) ); 
    
nv] = ( pv][ ] * pv][ ] ) - ( pv][ ] * pv][ ] ); 
        
    
/* in this stage you have normalvector(A;B;C) FOR PLANE, direction vector(l;m;n) FOR LINE, two points X,Y,Z,  two plane vectors, three points of plane with [x,y,z] 
    * and your task to find if LINE is intersection WITH PLANE. (crossing)
    * way to do this: 
    * LINE and PLANE intersect if scalar sumproduct of normalvector and directionvector not equals to 0.
    * nv[0]*vd[0]+nv[1]*vd[1]+nv[2]*vd[2] != 0   ->  direction and normal vector not perpendiculars => line intersect the plane 
    * if  nv[0]*vd[0]+nv[1]*vd[1]+nv[2]*vd[2] == 0, And nv[0]*flp[0][0]+nv[1]*flp[0][1]+nv[2]*flp[0][2]=0  -> line is inside plane and point flp[0] is inside plane. direction vector and normal vector are perpendiculars 
    * if  nv[0]*vd[0]+nv[1]*vd[1]+nv[2]*vd[2] == 0, And nv[0]*flp[0][0]+nv[1]*flp[0][1]+nv[2]*flp[0][2]!=0 -> line is parallel plane and point flp[0] is outside plane. direction vector and normal vector are perpendiculars 
    */

    /* if you need only INTERSECTION  just use this: */
    
if((nv[0]*vd[0]+nv[1]*vd[1]+nv[2]*vd[2]) != 0) return 1;

    
/* if you need intersection and also if line is inside use this:*/
   //if( (nv[0]*vd[0]+nv[1]*vd[1]+nv[2]*vd[2]) != 0) || ( (nv[0]*vd[0]+nv[1]*vd[1]+nv[2]*vd[2]) == 0 && (nv[0]*flp[0][0]+nv[1]*flp[0][1]+nv[2]*flp[0][2])==0) ) return 1;


    
return 0;

this is the way how to find if line is intersect with plane.
in case if you need to find D (for plane formula) use your:
d = - ( f_vNormal[ 0 ] * fPlanePoints[ 0 ][ 0 ] )
- (
f_vNormal[ 1 ] * fPlanePoints[ 0 ][ 1 ] )
- (
f_vNormal[ 2 ] * fPlanePoints[ 0 ][ 2 ] );
it is correct.
but your t also correct but in this case you use one point in two cases and if you put all expression in one line it will be something like this:
Ax+By+Cz+D=0
where
A:B:C -> normal vector:
nv[ 0 ] = ( pv[ 0 ][ 1 ] * pv[ 1 ][ 2 ] ) - ( pv[ 0 ][ 2 ] * pv[ 1 ][ 1 ] );
nv[ 1 ] = -1 * ( ( pv[ 0 ][ 0 ] * pv[ 1 ][ 2 ] ) - ( pv[ 0 ][ 2 ] * pv[ 1 ][ 0 ] ) );
nv[ 2 ] = ( pv[ 0 ][ 0 ] * pv[ 1 ][ 1 ] ) - ( pv[ 0 ][ 1 ] * pv[ 1 ][ 0 ] );
and x,y,z is: Xo,Yo,Zo.
D=-A*Xo-B*Yo-C*Zo

A* ( Xo + Ux * t ) + B * ( Yo + Uy * t ) + C* ( Zo + Uz * t )-A*Xo-B*Yo-C*Zo=0
A*Xo+A*Ux*t+B*Yo+B*Uy*t+C*Zo+C*Uz*t-A*Xo-B*Yo-C*Zo=0
A*Ux*t+B*Uy*t+C*Uz*t=0
t(A*Ux+B*Uy+C*Uz)=0
so your t=0 any way.
__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT

Last edited by AngeIII; 01-07-2013 at 12:29. Reason: add a some math code..
AngeIII is offline
Send a message via Skype™ to AngeIII
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:34.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode