🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help with a "sigma" notation equation

Started by
12 comments, last by Vilem Otte 5 years ago

 

That's a great picture, kind of explains what we're trying to do here. I just want to tie it into the formulas provided in the paper a bit. 

From what I understand he combines the projection of the box onto a plane and finding the minimum radius into one single formula which I linked previously. 

So to find the projection of the vertices and to calculate the minimum radius in one shot I can just use that right?

Would this the proper code for that formula?


vector vector_signum(const vector& inVec)
{


	vector out_vector = { (inVecF.x < 0) ? -1 : 1, (inVecF.y < 0) ? -1 : 1, (inVecF.z < 0) ? -1 : 1 };
	
    if (inVec.x == 0)
		out_vector.x = 0;
	else if (inVec.y == 0)
		out_vector.y = 0;
	else if (inVec.z == 0)
		out_vector.z = 0;

	return out_vector;
}

//find minimum radius
vector vertexRadiusA = vertexRadiusB = { 0, 0, 0};
for (int i = 0; i < 3; i++)
{
  vertexRadiusA += extentsA[i] * vector_signum(in_projectionAxis * axesA[i]) * (in_projectionAxis * axesA[i]);
  vertexRadiusB += extentsB[i] * vector_signum(in_projectionAxis * axesB[i]) * (in_projectionAxis * axesB[i]);
}

float radiusBoxA = vector_length(vertexRadiusA);
float radiusBoxB = vector_length(vertexRadiusB);

                                                                                          

 

Then I would just find the distance between the centers and project that on the plane as well


vector D = center1 - center0;

vector DprojectedOntoPlane = D * projection_axis; // D * L

 

Then I would simply compare if D*L > radiusBoxA + radiusBoxB to see if there are intersections and do that for all 15 projection axes. 


Is that a correct? 

 

Also another thing you said

1 hour ago, Vilem Otte said:

You need to test all 15 to properly reject collision, if you find any that has smaller distance than sum of radiuses, you can terminate the search (as if there is an intersection, you can find it there).

 

 

However what I understood the paper to say is that if a separating axis is found (that is if the R > r0 + r1) then we can quit the search, but if R < r0 + r1 (meaning the projections are intersecting on this axis) then we must still continue to test the other axes and if they intersect on all the axes then there is intersection. In other words I thought that if two objects are intersecting, their projections will intersect on any axis you project them onto. However if the objects are not intersecting, there will always be at least one axis in which the projections will not intersect, and if you find that axis then you can quit. But you're saying it's the other way around, I can quit the search after I find one intersecting axis? 

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement

Ok, I think I got it to work! I've rewritten the methods and it's looking good. Thanks so much for your help @Vilem Otte!

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

6 hours ago, VanillaSnake21 said:

However what I understood the paper to say is that if a separating axis is found (that is if the R > r0 + r1) then we can quit the search, but if R < r0 + r1 (meaning the projections are intersecting on this axis) then we must still continue to test the other axes and if they intersect on all the axes then there is intersection. In other words I thought that if two objects are intersecting, their projections will intersect on any axis you project them onto. However if the objects are not intersecting, there will always be at least one axis in which the projections will not intersect, and if you find that axis then you can quit. But you're saying it's the other way around, I can quit the search after I find one intersecting axis? 

I wrote it wrong - you are correct. If one axis is found to be separating there can be no collision (did a second read through now in the morning - and yes, if one separating axis is found there can clearly be no collision, like in the image I posted). For future reference I'm updating my previous post (in case someone reads it).

So, in the paper - he directly calculates the radius (as you noted), he does it in single step. You also don't need to divide by L.L (he explains why - you can compare against L.D, instead of distance), which saves you a division.

Now, for the code (I assume your operator * for vectors is defined as dot product (scalar product)), I believe this:


for (int i = 0; i < 3; i++)
{
  vertexRadiusA += extentsA[i] * vector_signum(in_projectionAxis * axesA[i]) * (in_projectionAxis * axesA[i]);
  vertexRadiusB += extentsB[i] * vector_signum(in_projectionAxis * axesB[i]) * (in_projectionAxis * axesB[i]);
}

Is equivalent to this:


for (int i = 0; i < 3; i++)
{
  vertexRadiusA += extentsA[i] * abs(in_projectionAxis * axesA[i]);
  vertexRadiusB += extentsB[i] * abs(in_projectionAxis * axesB[i]);
}

Anyways - out of personal curiosity - did the test work for you (how are you testing it?), and are you already calculating also contact points/penetration distance?. I remember that when I wrote simple physics engine, I was debug drawing collision boxes (different color for non colliding ones and different for colliding), contact points and penetration distance as line between contact points. It helped me to see it visually.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

This topic is closed to new replies.

Advertisement