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[ 2 ][ 3 ], Float:fpp[ 3 ][ 3 ]/*, &Float:d, &Float:t*/ )
{
new Float:vd[ 3 ], Float:pv[ 2 ][ 3 ], Float:nv[ 3 ];
vd[ 0 ] = flp[ 1 ][ 0 ] - flp[ 0 ][ 0 ];
vd[ 1 ] = flp[ 1 ][ 1 ] - flp[ 0 ][ 1 ];
vd[ 2 ] = flp[ 1 ][ 2 ] - flp[ 0 ][ 2 ];
pv[ 0 ][ 0 ] = fpp[ 0 ][ 0 ] - fpp[ 1 ][ 0 ];
pv[ 0 ][ 1 ] = fpp[ 0 ][ 1 ] - fpp[ 1 ][ 1 ];
pv[ 0 ][ 2 ] = fpp[ 0 ][ 2 ] - fpp[ 1 ][ 2 ];
pv[ 1 ][ 0 ] = fpp[ 2 ][ 0 ] - fpp[ 1 ][ 0 ];
pv[ 1 ][ 1 ] = fpp[ 2 ][ 1 ] - fpp[ 1 ][ 1 ];
pv[ 1 ][ 2 ] = fpp[ 2 ][ 2 ] - fpp[ 1 ][ 2 ];
/* correct */
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 ] );
/* 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.
__________________