Sign in to follow this  
eskimo456

Plane normalisation for collision detection

Recommended Posts

eskimo456    100
Hi there

I am attempting to do some 3D collision detection. I am using barycentric co-ordinates with a triangle to find if a collision has occoured. However this gives false positives due to being a 2D triangle. I figured the best way around this is to do a point to plane test to figure out if a collision could occour or not.

Simply flag false if the point is not near the plane. if point<1 to plane distance and 2D barycentric = true then collision = true.

I am checking my normals with the website http://jblanco_60.tripod.com/plane.html My normals are coming out as the point-normal form as opposed to the standard form.

In standered form my normals are 1,0,0 in point form it is 40000(x-35) = 0.

In standered normal form my results are 1x + 0y + 0z - 35 = 0

my test values are {35,0,50} {35,0,-150} {35,200,-150}
This should give me a giant triangle on the wall I am testing against.


My code for calculating my normals is

float * Collision::CalculateNormal(float point1[], float point2[],float point3[],float normal[3])
{
//calcualte cross product
float ux = point2[0] - point1[0];
float uy = point2[1] - point1[1];
float uz = point2[2] - point1[2];
float vx = point3[0] - point1[0];
float vy = point3[1] - point1[1];
float vz = point3[2] - point1[2];

//float normal[3]; // calculate cross products and assign to normal

normal [0] = ((vy*uz) - (vz*uy))*-1;
normal [1] = ((vz*ux) - (vx*uz));
normal [2] = ((vx*uy) - (vy*ux));


return normal;

}

Am I using the correct cross product and entering the values right?


my Barycentric co-ordinates are



bool Collision::BarryCentricEquation(float triA[],float triB[], float triC[],float point[])
{
Collision triangle;
float v0[] = {triC[0] - triA[0],triC[1] - triA[1],triC[2] - triA[2]};
float v1[] = {triB[0] - triA[0],triB[1] - triA[1], triB[2] - triA[2]};
float v2[] = {point[0] - triA[0],point[1] - triA[1],point[2] - triA[2]};

float dot00 = Calculation::dotProduct(v0,v0);
float dot01 = Calculation::dotProduct(v0,v1);
float dot02 = Calculation::dotProduct(v0,v2);

float dot11 = Calculation::dotProduct(v1,v1);
float dot12 = Calculation::dotProduct(v1,v2);

float bcc = 1/(dot00 * dot11 - dot01 * dot01);
float u = (dot11 * dot02 - dot01 * dot12) * bcc;
float v = (dot00 * dot12 - dot01 * dot02) *bcc;


if((u>0) && (v>0) && (u+v<1))
{
triangle.bccCollision = true;
}

else
{
triangle.bccCollision = false;
}
return triangle.bccCollision;

}


Finally my point to plane equation is

float Collision::PointToPlaneTest(float pointOfInterest[],float pointOnPlane[])
{
float pointX = pointOfInterest[0];
float pointY = pointOfInterest[1];
float pointZ = pointOfInterest[2];

float planePointA = pointOnPlane[0];
float planePointB = pointOnPlane[1];
float planePointC = pointOnPlane[2];


//(planePointA*pointX) + (planePointB*pointY) + (planePointC*pointZ);


float dist = (pointX*planePointA + pointY*planePointB + pointZ*planePointC);

return dist;
}


my values enter correctly and as I head towards the plane the distance does increase but at a very slow rate. I am assuming this is because I am using my normal as 40000 and not 1?



I am calculating the distance in the main for testing currently with this
float D = (Player.directionX + 1 + Player.directionZ + A)/sqrt((B[0]*B[0]) + (B[1]*B[1]) + (B[2]*B[2]));

Would it be better to just use this in my Collsion::PointtoPlane?

Any advice would be greatly appreciated
Many thanks in advance
Phil

P.S Sorry if this is the wrong place I was nsure if this counted as math or not



[Edited by - eskimo456 on November 30, 2010 4:24:47 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this