Advertisement

Distance from cylinder to polygon.

Started by February 28, 2002 11:38 PM
8 comments, last by FXO 22 years, 11 months ago
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
Advertisement
Thank you for the links
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..
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
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.
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.

             \  _____    V|     |     V     |     |V    |     | \   |     |__\x_|         \ // x = Closest point between plane and cylinder center.// \ = The triangles plane// V = The triangle  //If you take the closest point between the cylinders "outer hull"//and the plane, it would work in the case above, but not in the following:         \  _____    \|     |     x     |     |\    |     | V   |     |__V__|         V        

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
Advertisement
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
Sorry about the pictures, i wrote them with spaces, but they were formatted away.

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...

        \     ^ \   /  \ /   V---*----  


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
Yeah, that worked

(Also corrected the first line of my previous post.)

This topic is closed to new replies.

Advertisement