Jump to content
  • Advertisement
Sign in to follow this  
Kekko

mapping a cylinder on an axis

This topic is 5106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello How would you do to project a cylinder onto an axis, SAT-style? And secondly, which axes would you have to test against? My guess on the first question was CylinderHeight * Dot(CylinderY_Axis, TestedAxis) + CylinderWidth * Dot(CylinderX_Axis, TestedAxis); Where CylinderX_Axis is the vector from the point on the cylinder's y-axis closest to the object to be tested against to the object. Like so:
  
 | Y
 |       
 |______O
    X  /
 __   /  
|  | / A
|  |/
|  |
|__| C

// where:
// Y = cylinder's y-axis
// X = cylinder's x-axis
// A = vector from cylinder to object
// O = object to be tested against
// C = cylinder


Is this correct?

Share this post


Link to post
Share on other sites
Advertisement
what exactly are you trying to do?

can the problem be rephrased as: does vector x lie inside cylinder c? it seems like it might, if so i could help you. but i really dont have much of a clue as to what you are trying to archieve right now im affraid...

Share this post


Link to post
Share on other sites
As far as I'm aware SAT only works for polygonal objects and can't be applied to quadrics (spheres, cylinders, etc). For these you'll have to switch to an alternative algorithm. Or if you want a method that works for both then I recommend GJK.

Share this post


Link to post
Share on other sites
Eelco

I'm trying to find out if the cylinder is colliding with the object O, by using the Separating Axis Theorem.
And the axes X and Y are inside the cylinder.

Motorherp

Arr, methinks you're right. It works for sphere's though...
But what about projecting the cylinder and the other object onto a plane? This is actually what I've done with the cylinder right now. But how do you project a box onto a plane?


Share this post


Link to post
Share on other sites
i dont know if a cylinder works so well with SAT, since there is an infinite number of planes to check with no?

i think you need to use something else here, like the distance from a point to a line in 3d.

Share this post


Link to post
Share on other sites
The problem is that SAT works by using half space tests of the verts of one object against the planes of the second and vice versa (and then projections onto a cross axis). For a curved suface like on a cylinder or sphere there is no plane to do these tests against [edit: or rather an infinite amount like Eelco says]. I imagine that your sphere is actualy being approximated as a box as far as the algo is concerned.

Why exactly would you be projecting both objects onto a plane? For the plane testing part of the algo you use the planes which make up the polys of the objects. For the object which contains the plane you already know all its verts lie on one side (assuming its convex) and then you just do half space testing of the other objects verts. When it come to testing edge combinations you create an axis from the edges cross product and project all the verts onto that axis whilst testing for overlap. Maybe you could clarify a bit for me since I think I have the wrong end of the stick.

Share this post


Link to post
Share on other sites

Hmm, I think I came up with something that doesn't work... Still, the reason for projecting both objects onto a plane was that if a cylinder is projected onto a plane with a normal perpendicular to V1 and V2, where V1 is the axis of the cylinder and V2 is the vector from the cylinder to the box, we would now have two 2d-polygons to test for collisions instead. Only, this doesn't work...

But what would be the alternatives? To check the distance of all the vertices and edges of the box to the axis of the cylinder? Or would it be faster to approximate the cylinder to a cylinder-like polygon with 8 sides?

Share this post


Link to post
Share on other sites
For box to cylinder I'd loop through all the line segments which make up the box edges and calc the closest point on the edge line segment to the line segment which is the cylinders axis. Now the tricky part. If the projection of the point onto the cylinders axis lies outside the cylinders axis line segment then project the closest end of the cylinders line segment onto the box edge segment and use that instead since a cylinder has flat tops. Note that this akward step can be avoided if you use capsules rather than cylinders (this is what almost everyone does). Next determine the distance from this point to the cylinder axis and if this is less than the cylinder radius then you have an overlap. Once this is working you can think about getting a big speed boost out of it by modifying the algo to use only the boxes 3 axis segments instead of all the edge segments since these are always parallel to the corresponding edge segments anyway. Good luck

Share this post


Link to post
Share on other sites
Quote:
Original post by Kekko

Hmm, I think I came up with something that doesn't work... Still, the reason for projecting both objects onto a plane was that if a cylinder is projected onto a plane with a normal perpendicular to V1 and V2, where V1 is the axis of the cylinder and V2 is the vector from the cylinder to the box, we would now have two 2d-polygons to test for collisions instead. Only, this doesn't work...

But what would be the alternatives? To check the distance of all the vertices and edges of the box to the axis of the cylinder? Or would it be faster to approximate the cylinder to a cylinder-like polygon with 8 sides?

i think it's fastest to do cylinder analitically(as is).
First, you can easily enough reject most non-intersecting cases by computing distance to line segment along axis of cylinder.

Second, you need to test if any edge of your mesh intersects a cylinder(edit:do second as Motorherp said), and third, if any face of your mesh intersects cylinder axis or one of end circles ("edges" of cylinder).

Line-cylinder intersection is simple and you should be able to find it using google.

edit: 2Motorherp and my third part is also needed because if cylinder only penetrates faces of cube, your thingy will return no intersection.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!