Search code examples
mathvectorunity-game-enginephysicsgame-physics

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


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) {
     ...
}

Thank you for your help.


Solution

  • Thanks, however I found a solution from a method in Unity.

    Basically we only need 3 parameters : the top vertex, one vertex from the base and the base's face normal which I already had.

    Here's my solution :

    float GetPyramidAltitude (Vector3 top, Vector3 baseA, Vector3 baseNormal) {
        Vector3 topToBase = Vector3.Project(baseA - top, baseNormal);
        return topToBase.magnitude;
    }