Equation. Straight cutting the plane.
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:
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. |
Re: Equation. Straight cutting the plane.
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:
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. |
Re: Equation. Straight cutting the plane.
You can rotate the cube (2 opposite corners are enough), so yaw, pitch, roll are all 0, and rotate the point (same center and angles as in cube rotation). Then you can use the verification through sizes.
|
Re: Equation. Straight cutting the plane.
@AngeIII
I have a vector that is the origin of the box, the center... Then, I have other eight points that are the offset of the corners in relation with the origin. Example: PHP Code:
The origin of the cube doesnt change the offsets because the offset is in relation with this origin. Then I go over the corners taking them like a face ( 3 points ) for shape a plane, so i have to make a loop for 2 planes per cube face. I checked if I was taking wrong the values or making a mistake with the control of the origins, but it is ok because I drew each face taking 3 corners per face. But the calculation didn't work fine, it returns me like the aiming origin is crossing the planes everytime. I need only to know if the segment/line from player origin, to where he is aiming, is crossing each plane, so with this information I can solve the problem knowing if it crossed a odd or even number of planes. @Sylwester. I was thinking about that, that will work, but I want other way to do this before doing that. If there is no solution I'll try doing that. Greetings. Edit: I found the solution! With the data obtained with the first equation, I use these two STOCK's for verify if the collision point in inside 3 vertex, so, if it is, the line in colliding with one box's face, then if the number of faces that collides with the line is an odd number, the end point is inside the box, else the end point is outside and it continued after colliding with the box. But if the number of collisions is 0, the line never collisioned with the cube. PHP Code:
Bye. |
Re: Equation. Straight cutting the plane.
brr.. more efficiten way something like this:
PHP Code:
X, Y, Z = Vo + U*t really X,Y,Z = Vo-U*t for your if. // see my T calculation |
| All times are GMT -4. The time now is 13:34. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.