Jump to content
  • Advertisement
Sign in to follow this  
ZeRaW

Classifying Triangle to Cylinder in 3D

This topic is 4842 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

i am having some troubles classifying & finding the intersection between a triangle and a cylinder in 3D. if someone has already worked on this and can point me to some faqs, thanks.

Share this post


Link to post
Share on other sites
Advertisement
You can use the axis of the cylinder to do a ray/tri intersection test. The Moller Trumbore (google) method will give you barycentric coordinates of the intersection of the ray with the plane of the triangle. You can then convert the radius of the cylinder into a du and dv term (if you don't understand this, I could explain it more), so that you can test the area within 'du' units outside the triangle in barycentric coordinates to account for a 'width' to the ray.

My guess is that this will give you a very good approximation, but it will not be exact. For instance, along the hypoteneuse (edge opposite barycentric origin) I feel like this will evaluate to linearly interpolating a squared term. Still, how exact do you need?

Share this post


Link to post
Share on other sites
well i need it in a geometric library so i need it pretty exact.
so i f u please explain to me more , thank you.

Share this post


Link to post
Share on other sites
It also depends what you need as an intersection result. DO you need some sort of contact points? Or merely to know if it intersects?

here is a good link for intersection stuff.

http://www.realtimerendering.com/int/

Share this post


Link to post
Share on other sites
You could calculate the "closest approach" (google) of the cylinder axis segment with each edge of the triangle, and with the plane of the triangle (imagine big triangle with small cylinder passing through the middle perpendicularly). The smallest of these distances can be checked against the radius of the triangle.

This will be more precise but slower and more potential instability (lots of cross products on the closest approach calculations). Or yeah, just go look at oliii's link :)

Share this post


Link to post
Share on other sites
the website:
http://www.realtimerendering.com/int/
requires me to email the author , i tried that and he is not available till september 12 which is a very long time (because i need it badly).
If somebody can just explain mathematicly or in steps how to find the intersection between a cylinder and a triangle in 3D I would apprectiate it.

Share this post


Link to post
Share on other sites
analytically

point is on triangle V0, V1, V2 if

P = V0 + u * (V1 - V0) + v (V2 - V0)
0 < u < 1
0 < v < 1
0 < u + v < 1

P is on cylinder (C, D, r, h) if

((P - C) x D)^2 = r^2

and

t = ((P - C) . D)
0 < t < h

ok, so that is unsolvable.

another way. Find the closest points from a infinite line (the line passing through your cylinder) with the triangle. Assuming you know how, it should be straight forward after that.

ok, imagine this



// very similar to D.eberly's point-triangle distance routine
float GetLineTriangleDistanceSquared(Vector C, Vector D, Vector V0, Vector V1, Vector V2, float& t, float& u, float& v)
{
....
}

bool CylinderTriangleIntersect(Vector C, Vector D, float r, float h, Vector V0, Vector V1, Vector V2)
{
float t, u, v, dist2;
dist2 = GetLineTriangleDistanceSquared(C, D, V0, V1, V2, t, u, v);

// distance of infinite line to triangle > cylinder radius
if (dist2 > r*r) return false;

// point on triangle
Vector Ptri = V0 + (V1 - V0) * u + (V2 - V0) * v;

// point on cylinder's internal segment
float tseg = clampf(t, 0, h);
Vector Pseg = C + D * tseg;

// capsule test. more accurate than just an infinite line
dist2 = (Pline - Ptri).GetMagnitudeSquared();
if (dist2 > r*r) return false;

// find out if the point on triangle is inside the cylinder
float ttri = (Ptri - C) * D;

// nope. not within the caps
if (ttri < 0 || ttri > h)
{
return false;
}

// yay!
return true;
}




and you can extract useful information of a function like that, such as potential contact points.

problems. If the cylinder is flat on the triangle plane. The line-triangle closest point pair will not be accurate.

in that case, here is a thought.

let N be the triangle normal.

Find the intersection segment between the plane (C, (N x D)) and the triangle.

test if that segment intersects the cylinder.

I wonder if that method would work in any case...

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!