Raised This Month: $ Target: $400
 0% 

Equation. Straight cutting the plane.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
fearAR
Veteran Member
Join Date: Oct 2010
Old 01-06-2013 , 20:37   Equation. Straight cutting the plane.
Reply With Quote #1

Ok, my problem is the following, I can't found the way to know if a point is inside a cube defined by 8 points ( each corner is a point ), at the same time the cube is conformed by 6 faces, and each face contains 2 meshes.

I can't use the verification through sizes, because the cube has the property of turn in its euclidean axis, pitch/yaw/roll.

Therefore it isn't convenient to me, as there are cases where the points is outside the cube, and it will return me a wrong result, like it is inside.

For solve this problem, I'm using the way "intersection straight/plane", in fact it isn't a straight, it is a segment, which has a start and an end. Anyway, the rules are the following:

* If the straight cut the cube's faces in an odd number of times, it implies that the final point is inside the cube.

* If the straight cut the cube's faces in an even number of times, it implies that the final point crossed the cube and continued.

* If the straight didn't cut any face, it never passes throw the cube, therefore it is discarded.

Illustrative picture:
[IMG]http://img717.**************/img717/7564/cuboy.png[/IMG]

For doing this I need a calculation, where I obtain the normal vector to the plane, and then, I clear it.

For give an example I guide myself with this video, but It doesn't work well, or I didn't applied it well.
http://www.youtube.com/watch?v=3pj3vwpeFro

Finishing it, I'm giving you the function that I recreated, and the determination of the calculation.

U = direction vector ( End - Start )
Xo, Yo, Zo = starting vector
a,b,c = normal vector to the plane

aX + bY + cZ + D = 0

Vo = Starting vector
U = Direction vector
t = Direction vector's scalar
X, Y, Z = Vo + U*t

Replacing...

a * ( Xo + Ux * t ) + b * ( Yo + Uy * t ) + c * ( Zo + Uz * t ) + D = 0

Separating the terms...

aXo + aUxt + bYo + bUyt + cZo + cUzt + D = 0

Move the values with t to the other hand.

aXo + bYo + cZo + D = -( aUxt ) -( bUyt ) - ( cUzt )

aXo + bYo + cZo + D = t( -aUx - bUy - cUz )

t = ( aXo + bYo + cZo + D ) / ( -aUx - bUy - cUz )

In fact, in programming language...

PHP Code:
/* I go around the bucle, and takes the corners and his 2 adjacent points for shape the plane */

/*And then I apply this results to the following STOCK:*/

stock intersection_lineplane( const Float:fLinePoints][ ], Float:fPlanePoints][ ], &Float:d, &Float:)
{
    new 
Float:f_vDirection], Float:f_vPlane][ ], Float:f_vNormal];
    
    
f_vDirection] = fLinePoints][ ] - fLinePoints][ ];
    
f_vDirection] = fLinePoints][ ] - fLinePoints][ ];
    
f_vDirection] = fLinePoints][ ] - fLinePoints][ ];
    
    
f_vPlane][ ] = fPlanePoints][ ] - fPlanePoints][ ];
    
f_vPlane][ ] = fPlanePoints][ ] - fPlanePoints][ ];
    
f_vPlane][ ] = fPlanePoints][ ] - fPlanePoints][ ];
    
    
f_vPlane][ ] = fPlanePoints][ ] - fPlanePoints][ ];
    
f_vPlane][ ] = fPlanePoints][ ] - fPlanePoints][ ];
    
f_vPlane][ ] = fPlanePoints][ ] - fPlanePoints][ ];
    
    
f_vNormal] = ( f_vPlane][ ] * f_vPlane][ ] ) - ( f_vPlane][ ] * f_vPlane][ ] ); 
    
f_vNormal] = -* ( ( f_vPlane][ ] * f_vPlane][ ] ) - ( f_vPlane][ ] * f_vPlane][ ] ) ); 
    
f_vNormal] = ( f_vPlane][ ] * f_vPlane][ ] ) - ( f_vPlane][ ] * f_vPlane][ ] ); 
        
    
=     - ( f_vNormal] * fPlanePoints][ ] )      
        - ( 
f_vNormal] * fPlanePoints][ ] )     
        - ( 
f_vNormal] * fPlanePoints][ ] );
                    
    
=     ( ( f_vNormal] * fLinePoints][ ] ) + ( f_vNormal] * fLinePoints][ ] ) + ( f_vNormal] * fLinePoints][ ] ) + 
        / ( - ( 
f_vNormal] * f_vDirection] ) - ( f_vNormal] * f_vDirection] ) - ( f_vNormal] * f_vDirection] ) );
    
        
/* This conditional is to know if the results is in the range of the segment and now the straight */
    
if( 0.0 1.0 ) return 1;
    
    return 
0;

Greetings! I expect for your replies.

PD: the calculation of the normal vector ( cross product ) to the plane is perfect, because I represented it with a Temp Entity TE_BEAMPOINTS, and it is perfect.
The problem can proceed from D to T, and I can't found the solution.
__________________
~~~~ NPC AI ~~~~

[ Pathfinding - OK ]
[ Citizen AI - OK ]
[ Handle Weapons - --- ]
fearAR is offline
Send a message via MSN to fearAR
 



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