2d/3d math help (differential calculus)..

Community Forums/General Help/2d/3d math help (differential calculus)..

matibee(Posted 2012) [#1]
I'm not sure this is the place to post this but someone might be able to help..

I'm working on some 3d collision code for sphere vs triangle, cylinder vs triangle, cone vs triangle etc. It's special case stuff where these primitives are cast straight down from the sky and given their X,Z positions I only need to solve the height of first contact. Contacts with triangle faces or vertices is easy enough but contacts with their edges is a bit more involved.

I've got cylinder and sphere code working nicely. Basically if a triangle edge overlaps a cylinder or a sphere it truncates it, the size of the truncation is used to find a point on the triangle edge...



But the section through a cone is very different to the simple sections through a cylinder or a sphere -- they're a function of the cone angle and the distance between the truncation plane and the cone centre.



This'll be where the differential calculus comes in but it's been a looong time since I did that at uni.

My question is (which probably underlines my lack of calculus experience), given we know the required tangent, can we rearrange the formula for finding the tangent to find an x or y position on it? Otherwise, am I going to have to 'walk' the curve until I find a matching tangent?

Any help appreciated :) I've only just started down this road, and I'll solve it in time. I'm just looking to reduce that time if I can ;)

Cheers

Last edited 2012


Derron(Posted 2012) [#2]
I cannot imagine why calculus should be needed?

Couldn't the upper part of the cone/ 2d-triangle be splitted into different easy to calculate objects ? - triangles, trapezoid, ...

The theorem of intersecting lines is also a thing which may help to get a nice and short formula. May be some rotations or further information (last animation position, ...) are needed.

Just some ideas as I do not have the time now to do more things in depth.


PS: I do not really know what the points you marked are in reality. Do you want to know the edge cutting the hit object? Or what is the exact position you want to calculate (in your cone example the height would be the most lower part of the triangle hitting the line).

bye
Ron


Floyd(Posted 2012) [#3]
I think the key idea is to use the axis of the cone. This is the line through the apex and "down the middle".

As the triangle edge descends the first point of contact with the cone is the one you seek. But don't stop there. Imagine the edge continuing until it hits the axis. Now go back to thinking of the edge stopping when it hits the cone. Consider the line from the intersection point on the axis to the tangency point where the edge touches the cone. The line is perpendicular to the edge at this point.

The point on the axis is easy to calculate. The orientation of the descending edge is known. It shouldn't be too hard to work out the details using the perpendicularity of the line from the axis point to the point where the edge contacts the cone.

That's as much progress as I can make without rolling up my sleeves and doing some real work.


matibee(Posted 2012) [#4]
Thanks for your thoughts guys. The more I look at this the more I need calculus to truly solve it (although I may opt to perform half testing for now as that's simpler.)

If the edge is flat (same height both ends) finding the intersection is easy but as the edge becomes steeper the contact point moves further along the curve (see final part of diagram above) but this also has the effect of moving the contact point further from the axis. I think that simultaneously solving the height and the distance from the axis can only be done through the one common factor we have and that's the angle of the edge. The true intersection is where the angle of the edge and the slope of the curve match.

The function for the curve (for a cone of inifite height) is ( Sqr( x * x + d * d ) / Tan( a ) ) where d is the distance from the cone axis (length of blue line in first part of cone/edge diagram above) and a is the cone angle.

Dave Eberly's geometric tools site also mentions this curve of seperation: www.geometrictools.com/Documentation/IntersectionTriangleCone.pdf (see Section 3 - Finding Intersection.)

BTW - this is not for real time use but accuracy is pretty important (to 4 decimal places.) Also (just to reiterate), the contact point shown in the final diagram is the only point on the surface of the cone that may hold true for a known edge, known cone and known X and Z positions.

Thanks for listening :)

Last edited 2012