# comjmemathPlane.java bug?

Hi

Congratulation, I'am very pleased with jMonkeyEngine.

I think, I have found a bug in comjmemathPlane.java, pseudoDistance function:

Line 148: original

return normal.x*point.x + normal.y*point.y + normal.z*point.z - constant;
repaired line
return normal.x*point.x + normal.y*point.y + normal.z*point.z + constant;

Please let me know, is it right?
Isn't is a very much used function, not to find it by anyone?

Thanks
Fugedi Zsolt
Hungary

No, it is correct as it is.  The constant is defined as being equal to the plane normal DOT any point on the plane.  Therefore if we subtract it from "normal DOT some point in space" we get a positive result if the point is in front of the plane and a negative result if it is behind the plane.

renanse said:

No, it is correct as it is.  The constant is defined as being equal to the plane normal DOT any point on the plane.  Therefore if we subtract it from "normal DOT some point in space" we get a positive result if the point is in front of the plane and a negative result if it is behind the plane.

If I define a plane paralel with XY plane, and two points before and behind it, whichSide function should return different values.
The version as it is in the present lib, for me the result is 1 and 1, same values.
If I change the code like I said, the result will be right.

public static void main(String[] args) throws Exception
{
Vector3f t1 = new Vector3f( 0,0,2 );
Vector3f t2 = new Vector3f( 1,0,2 );
Vector3f t3 = new Vector3f( 1,1,2 );
Plane p1 = new Plane();
p1.setPlanePoints( t1,t2,t3 );

Vector3f point1 = new Vector3f( 0,0,1 );
Vector3f point2 = new Vector3f( 0,0,3 );

System.out.println( "p1,1:" + p1.whichSide( point1 ) );
System.out.println( "p1,2:" + p1.whichSide( point2 ) );
}

The reason your code returns the same value both times is because of a bug in setPlanePoints, not pseudoDistance.  It's never come up in jME because jME does not use setPlanePoints.  The bug is that the constant is created negative, when it should just be normal DOT v1.  So, at least there was a bug in Plane, just not what you thought.

I'll have it fixed in the next cvs checkin.

i'm using rc1 and the bug still is there. i get distance 903 where it should be -3.

```    public void setPlanePoints(Vector3f v1, Vector3f v2, Vector3f v3) {         normal.set(v2).subtractLocal(v1);         normal.crossLocal(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z).normalizeLocal();         constant = -(normal.x * v1.x + normal.y * v1.y + normal.z * v1.z);     } ```

The fix for that was checked in on Aug 2nd. (3 weeks before rc1):

```public void setPlanePoints(Vector3f v1, Vector3f v2, Vector3f v3) {         normal.set(v2).subtractLocal(v1);         normal.crossLocal(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z)                 .normalizeLocal();         constant = normal.dot(v1);     }```