Distance from cylinder to polygon.
Hey there!
Does anybody have any pointers to documentation/democode on how to determine the distance from a cylinder to a polygon?
I''ve been looking for two days now, and I can''t find anything useful.
Thanks!
/Fredrik Olsson
check out http://www.realtimerendering.com/int/
or http://www.magic-software.com/Distance3D.html
or http://www.magic-software.com/Distance3D.html
Thank you for the links ![](smile.gif)
There was a lot of useful information, but I can''t find any information on getting the closest line between a cylinder and a polygon, perhaps you cant..
![](smile.gif)
There was a lot of useful information, but I can''t find any information on getting the closest line between a cylinder and a polygon, perhaps you cant..
March 01, 2002 08:25 AM
I''m not sure about this solution, but I think it would work.
First of you can asume the polygon is a simple triangle (in other case you could triangulat the polygon and runt for each triangle)
Now determind the distance between the cylinder and the plane the polygon represents, this gives 2 solutons, either they intersect or they are parallell. This distance can be calculated as the distance between the plane and the center line of the cylinde - radius
If the intersection point is on the polygon (point on polygon) you have an direct intersection in other case the shortest distance must be between one of the edges and the cylinder
So it falls down do determining the distance between the edge lines and the cylinder. This can be done by simple determinding the shortest distance between the line and the cylinder center line, then check if this shortest distance is reached within the edge line (and not its extrapolation). Last you will have to ckeck the distance between the vertexes and the cylinde (point-line distance)
So it all works out as:
*Distance plan-line, check intersection point in poly
*Distance edge-line, check intersection point on line
*Distance vertex-line
all these distances/intersection can be found in books on algebra / the ner
/Gustav
First of you can asume the polygon is a simple triangle (in other case you could triangulat the polygon and runt for each triangle)
Now determind the distance between the cylinder and the plane the polygon represents, this gives 2 solutons, either they intersect or they are parallell. This distance can be calculated as the distance between the plane and the center line of the cylinde - radius
If the intersection point is on the polygon (point on polygon) you have an direct intersection in other case the shortest distance must be between one of the edges and the cylinder
So it falls down do determining the distance between the edge lines and the cylinder. This can be done by simple determinding the shortest distance between the line and the cylinder center line, then check if this shortest distance is reached within the edge line (and not its extrapolation). Last you will have to ckeck the distance between the vertexes and the cylinde (point-line distance)
So it all works out as:
*Distance plan-line, check intersection point in poly
*Distance edge-line, check intersection point on line
*Distance vertex-line
all these distances/intersection can be found in books on algebra / the ner
/Gustav
I did the maths for this a year ago when looking whether/how to add cylinders into our collision detection routines.
The outcome was I didn''t: the maths was straightforward but required you to solve a quartic equation to resolve the collsion, something that''s very expensive to do in real time. So I would not recommend it but if you want to try...
Write down an equation for the cylinder surface. Then write equations for the line giving, e.g., x and y in terms of z. The line intersects the cylinder if substituting these into the cylinder equation gives you an equation that can be solved. You then substitute this back into the line to find the points, and compare it to the height of the cylinder to find whether it intersects the curved surface only or the ends as well.
The outcome was I didn''t: the maths was straightforward but required you to solve a quartic equation to resolve the collsion, something that''s very expensive to do in real time. So I would not recommend it but if you want to try...
Write down an equation for the cylinder surface. Then write equations for the line giving, e.g., x and y in terms of z. The line intersects the cylinder if substituting these into the cylinder equation gives you an equation that can be solved. You then substitute this back into the line to find the points, and compare it to the height of the cylinder to find whether it intersects the curved surface only or the ends as well.
John BlackburneProgrammer, The Pitbull Syndicate
Gustav - If you calculate the closest point between a cylinder and a plane, you could end up with a point outside the triangle, but still have a collision.
Perhaps I missed something..
Johnb - Perhaps i should use a sphere for collision instead, thanks for sharing your experience.
I don't know if a sphere collision model would be sufficiant,
I believe that most games use cylinder, but I might be wrong.
Edit - fixed spaces
Edit - replaced "cylinder and a triangle" with "cylinder and a plane" in the first sentance.
Edited by - FXO on March 4, 2002 1:38:41 AM
|
Perhaps I missed something..
Johnb - Perhaps i should use a sphere for collision instead, thanks for sharing your experience.
I don't know if a sphere collision model would be sufficiant,
I believe that most games use cylinder, but I might be wrong.
Edit - fixed spaces
Edit - replaced "cylinder and a triangle" with "cylinder and a plane" in the first sentance.
Edited by - FXO on March 4, 2002 1:38:41 AM
March 03, 2002 01:31 PM
I don''t really understand your pictures. But after having read trou my solution again I''ve realized that it will fail if the triangle is completely contained within the cylinder
The solution to this would be to find the largest distance from the ''cylinder center line'' to the polygon and check if its greater then the radius.... but the code seems to be getting more and more time consuming
/Gustav
The solution to this would be to find the largest distance from the ''cylinder center line'' to the polygon and check if its greater then the radius.... but the code seems to be getting more and more time consuming
/Gustav
Sorry about the pictures, i wrote them with spaces, but they were formatted away.
Does anybody know how to preserv spaces?
Does anybody know how to preserv spaces?
quote:
Original post by FXO
Sorry about the pictures, i wrote them with spaces, but they were formatted away.
Does anybody know how to preserv spaces?
Maybe using the [ source ][ /source ] block (remove spaces)? Let's see...
|
Let's see if that was preseved...
[EDIT]
It seems to have been preserved, so use the source, /source blocks.
SS
Edited by - Axter on March 3, 2002 12:28:22 AM
SS
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement