plane3d using inverted D (dist)?!

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

plane3d using inverted D (dist)?!

Post by shadowslair »

Well, not really a bug, since it`s working, but I think it`s kinda weird (in the plane3d class) to work with negative D (for distance) value all the time. Seems wrong to me. I may be wrong though... :roll:

Code: Select all

//! Recalculates the distance from origin by applying a new member point to the plane.
		void recalculateD(const vector3d<T>& MPoint)
		{
			D = - MPoint.dotProduct(Normal);
		}
Like if I create the plane from a triangle with clockwise sequence of the verts, it should be sth like;

Code: Select all

core::plane3df p;
p.Normal = (tri.pointB - tri.pointA).crossProduct(tri.pointC - tri.pointA);
p.D = p.Normal.dotProduct(tri.pointA);
If I create it via constructor with three points I get negative D. Am I doing wrong?!
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The plane3d template has a constructor to do exactly what you want, and the triangle3d template has an accessor for the same thing... just use them.

Code: Select all

// use the triangle accessor
plane3df p = tri.getPlane();

// or use the plane3d constructor
plane3df p (tri.pointA, tri.pointB, tri.pointC);
If you follow the code, you'll see the calculation of the plane is as follows

Code: Select all

p.Normal = (tri.pointB - tri.pointA).crossProduct(tri.pointC - tri.pointA);
p.Normal.normalize();

p.D = -tri.pointA.dotProduct(p.Normal);
As mentioned previously, just stay away from the member data and use the class functionality provided and you don't have to worry about how to calculate D.

That said, D is supposed to be the distance from the origin to the plane (according to the comment in plane3d.h), but it is really the distance from the nearest point on the plane to the origin...

Code: Select all

vector3d<T> getMemberPoint() const
{
   return Normal * -D;
}
Travis
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Hi, Travis,

Yeah, I know about the plane constructor(as I mentioned before) and triangle function, I know well what D is used for and how to calculate it - by the way I almost know by heart all the math classes already. :lol: (which are some nice basis by the way.)

Recently I`m learning more about collision detection and how things are done. Browsing through some code, algorithms and on, I figured out that many formulaes aren`t working "as-is" with "D" stored this way. I checked some other implementations of plane classes and none of them was doing it this way, that`s why I was asking this. Of course I can easily put a minus sign in front of D in all formulaes, but I was wondering why it is done this way, and that it could possibly lead to some issues like when passing an irr plane to some collision library for example and on. Well, it doesn`t really matter that much.

Anyway, thanks and sorry for bother! :wink:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Post Reply