# Find the altitude of an irregular tetrahedron given all 4 vertex positions

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

## Recommended Posts

I have an irregular tetrahedron using 4 vertices.

I need to find out the altitude given that one specific vertex is the top and the others are the base.

Basically the height would be the shortest distance from the top to its base creating a 90 degrees angle. It should be a simple math question but I cannot find anything on Google.

I am looking for an optimized function that looks like this :

float GetPyramidAltitude (Vector3 top, Vector3 baseA, Vector3 baseB, Vector3 baseC) { ... }

##### Share on other sites
Pick the top vertex however you determine "top" (such as your first parameter in that function you have there).
If the other three vertices are coplanar (well, they're always coplanar, just make sure they're not degenerate into a point or line anyway) get the normal of the plane they lie on.
Take any edge from one base vertex to the top vertex and project that line onto the plane normal.
Take the magnitude of the resulting line.

Simplify and remove the unused portions of the calculation (i.e. the whole projected vector isn't needed, just the magnitude).

There are likely much simpler ways to do this that I don't know about since I'm not a math person, but that's an intuitive geometric way of going about it.

It seems like you could give a valid answer for the degenerate cases (all three base vertices at the same location | all base vertices collinear) as well:

- Point case: return the distance between top and any base vertex.
- Line case: solve the 3D problem the same way in 2D, just without the degenerate vertex (you can project along the base line and then subtract that from the top-base vector to get the vector along the "normal").

Early-out:
- If top is the same as any other vertex, return 0. Edited by Nypyren

##### Share on other sites

Thanks it worked like a charm !

• ### What is your GameDev Story?

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

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634046
• Total Posts
3015219
×