jmgunn87 118 Report post Posted March 9, 2010 I believe the d value of a plane in directx's D3DXPLANE structure is the distance from the plane to the origin. How do i calculate this value without using directx? i have forgotten! Thanks in advance 0 Share this post Link to post Share on other sites
Hodgman 51429 Report post Posted March 9, 2010 How do you calculate it from what? What are you starting from that you have to find a plane equation from? 0 Share this post Link to post Share on other sites
jmgunn87 118 Report post Posted March 9, 2010 it is my understanding that the plane.d value should be equal to the distance of the plane from the co-ordinate system.I am entering a plane normal for abc. what do i add for d? 0 Share this post Link to post Share on other sites
nullsquared 126 Report post Posted March 9, 2010 Quote:Original post by jmgunn87it is my understanding that the plane.d value should be equal to the distance of the plane from the co-ordinate system.I am entering a plane normal for abc. what do i add for d?d is whatever you want it to be. If the plane is facing upwards, and you make d=5, then the plane will be 5 units above the origin.If you have some other criteria for creating the plane, such as creating it based on three points, then things are different. You would create the normal as a cross product of two sides of the triangle, and then project one of the points onto the normal to get the distance. 0 Share this post Link to post Share on other sites
howie_007 285 Report post Posted March 10, 2010 Quote:Original post by jmgunn87How do i calculate this value without using directx? i have forgotten!This is how you would calculate the plane on your own.A plane is simply the dot product of the surface normal and one of the verts of the triangle (or quad) face. I'm not sure what you would use it for by itself but this is usually used as a check to see if a given point has pierced a plane.To check a point against a plane, you create a dot product from the normal of the plane and the point and then add both dot products. If the value is less then 0.0, the point has pierced the plane. The d value can simply be added in with the dot products. Think of the d value as padding if you need it in the case of collision detection. If you need the condition to trigger early or late. The d value does not have to be used.See the below code./************************************************************************* desc: Get the angle of the point to the plane. Simple check* because a value less then 0.0 means the point is on the* other side of the plane.** param: CPoint & point - point to test against** ret: float - angle of point to plane************************************************************************/float CFace::AngleToPlane( CPoint & point ){ // Here we define the plane for a polygon edge. In simpler terms, we are getting // the angle of the polygon's normal to one of it's points which is always 90 degrees. float polygonPlane = -normal.GetDotProduct( vert[0] ); // Create a dot product from the face normal and the point and add // both dot products. return normal.GetDotProduct( point ) + polygonPlane;} // AngleToPlane/************************************************************************* desc: Is this point facing the front of the plane** param: CPoint & point - point to test against** ret: bool - true if facing plane************************************************************************/bool CFace::IsFacingPlane( CPoint & point ){ if( AngleToPlane( point ) < 0.0f ) { return false; } else { return true; }}/************************************************************************ * desc: Get the dot product ** param: CPoint & point** return: float - distance between two points************************************************************************/float _fastcall GetDotProduct( CPoint & point ){ // Calculate the dot product between two points // Can also be the surface normal return( ( x * point.x ) + ( y * point.y ) + ( z * point.z ) );} // GetDotProduct/************************************************************************* desc: Calculate the cross product that is then* normalized. This is the normal of the polygon face.* This function assumes all vertex points are unique.* Also, this calculation of the cross product produces* a normal with more precesion because it uses all 3 points* on the triangle surface.************************************************************************/void CFace::CalcSurfaceNormal(){ double X1( vert[ 0 ].x ); double Y1( vert[ 0 ].y ); double Z1( vert[ 0 ].z ); double X2( vert[ 1 ].x ); double Y2( vert[ 1 ].y ); double Z2( vert[ 1 ].z ); double X3( vert[ 2 ].x ); double Y3( vert[ 2 ].y ); double Z3( vert[ 2 ].z ); // Calculate the cross product using all three points on the triangle double x( Y1 * ( Z2 - Z3 ) + Y2 * ( Z3 - Z1 ) + Y3 * ( Z1 - Z2 ) ); double y( Z1 * ( X2 - X3 ) + Z2 * ( X3 - X1 ) + Z3 * ( X1 - X2 ) ); double z( X1 * ( Y2 - Y3 ) + X2 * ( Y3 - Y1 ) + X3 * ( Y1 - Y2 ) ); // this is to show how you can create the cross product with just two // points from the triangle face. Still works but not as precise. // May cause problems. //x = ( (Y1 * Z2) - (Z1 * Y2) ); //y = -( (X1 * Z2) - (Z1 * X2) ); //z = ( (X1 * Y2) - (Y1 * X2) ); // Calculate the length of the vector double length( sqrt( (x*x) + (y*y) + (z*z) ) ); // length can't be zero otherwise you'll get a divided by 0 error. // The normalizing part is the (n.x / length) if( length != 0.0 ) { // Normalize the normal. Sounds silly hu? normal.x = (float)( x / length ); normal.y = (float)( y / length ); normal.z = (float)( z / length ); } else { assert(!("Zero length vector!")); }} // CalcSurfaceNormal// You could do this// Add some padding so we satisfy the check early (or late if negative)float d = 10.0f;float foo = AngleToPlane( CPoint(45,23,182) ) + d [Edited by - howie_007 on March 10, 2010 9:24:21 AM] 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted March 10, 2010 Quote:Original post by jmgunn87it is my understanding that the plane.d value should be equal to the distance of the plane from the co-ordinate system.That depends on how you define "distance". In fact, d is the multiple you have to scale the plane's normal vector with, so that the normal vector bounds that point on the plane that is closest to the origin of the co-ordinate frame all the math is done in.So the "distance" is 1st defined as distance of the closest point, is 2nd dependend on the length of the normal vector (although those is usually chosen to be of unit-length), and 3rd may also be negative (in case that the normal vector points towards the origin of the co-ordinate frame instead of away from it, so that the vector that binds the closest point is anti-parallel to the normal vector).To compute d, chose any point o on the plane, and dot-multiply its vector with the plane's normal:o . n =: dThis comes from the formula to compute the "distance" of any point p in space from the plane( p - o ) . nwhere after eleminating the parentheses= p . n - o . n= p . n - dBTW: Notice please that using -d as in-o . n =: dso thatp . n + dis another convention. 0 Share this post Link to post Share on other sites