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[ 2 ][ 3 ], Float:fPlanePoints[ 3 ][ 3 ], &Float:d, &Float:t )
{
new Float:f_vDirection[ 3 ], Float:f_vPlane[ 2 ][ 3 ], Float:f_vNormal[ 3 ];
f_vDirection[ 0 ] = fLinePoints[ 1 ][ 0 ] - fLinePoints[ 0 ][ 0 ];
f_vDirection[ 1 ] = fLinePoints[ 1 ][ 1 ] - fLinePoints[ 0 ][ 1 ];
f_vDirection[ 2 ] = fLinePoints[ 1 ][ 2 ] - fLinePoints[ 0 ][ 2 ];
f_vPlane[ 0 ][ 0 ] = fPlanePoints[ 0 ][ 0 ] - fPlanePoints[ 1 ][ 0 ];
f_vPlane[ 0 ][ 1 ] = fPlanePoints[ 0 ][ 1 ] - fPlanePoints[ 1 ][ 1 ];
f_vPlane[ 0 ][ 2 ] = fPlanePoints[ 0 ][ 2 ] - fPlanePoints[ 1 ][ 2 ];
f_vPlane[ 1 ][ 0 ] = fPlanePoints[ 2 ][ 0 ] - fPlanePoints[ 1 ][ 0 ];
f_vPlane[ 1 ][ 1 ] = fPlanePoints[ 2 ][ 1 ] - fPlanePoints[ 1 ][ 1 ];
f_vPlane[ 1 ][ 2 ] = fPlanePoints[ 2 ][ 2 ] - fPlanePoints[ 1 ][ 2 ];
f_vNormal[ 0 ] = ( f_vPlane[ 0 ][ 1 ] * f_vPlane[ 1 ][ 2 ] ) - ( f_vPlane[ 0 ][ 2 ] * f_vPlane[ 1 ][ 1 ] );
f_vNormal[ 1 ] = -1 * ( ( f_vPlane[ 0 ][ 0 ] * f_vPlane[ 1 ][ 2 ] ) - ( f_vPlane[ 0 ][ 2 ] * f_vPlane[ 1 ][ 0 ] ) );
f_vNormal[ 2 ] = ( f_vPlane[ 0 ][ 0 ] * f_vPlane[ 1 ][ 1 ] ) - ( f_vPlane[ 0 ][ 1 ] * f_vPlane[ 1 ][ 0 ] );
d = - ( f_vNormal[ 0 ] * fPlanePoints[ 0 ][ 0 ] )
- ( f_vNormal[ 1 ] * fPlanePoints[ 0 ][ 1 ] )
- ( f_vNormal[ 2 ] * fPlanePoints[ 0 ][ 2 ] );
t = ( ( f_vNormal[ 0 ] * fLinePoints[ 0 ][ 0 ] ) + ( f_vNormal[ 1 ] * fLinePoints[ 0 ][ 1 ] ) + ( f_vNormal[ 2 ] * fLinePoints[ 0 ][ 2 ] ) + d )
/ ( - ( f_vNormal[ 0 ] * f_vDirection[ 0 ] ) - ( f_vNormal[ 1 ] * f_vDirection[ 1 ] ) - ( f_vNormal[ 2 ] * f_vDirection[ 2 ] ) );
/* This conditional is to know if the results is in the range of the segment and now the straight */
if( 0.0 < t < 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.
__________________