# Classifying Triangle to Cylinder in 3D

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

## 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 on other sites
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 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 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 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 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 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 routinefloat 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...

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634107
• Total Posts
3015549
×