Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

Help with a "sigma" notation equation

Recommended Posts

Posted (edited)

 

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? 

Edited by VanillaSnake21

Share this post


Link to post
Share on other sites
Advertisement
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.

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  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!