How to find the height of a 2D coordinate on a 3D triangle?

1k Views Asked by At

I would like to know how to dertermine the $Y$ coordinate of a point $M(X,Y,Z)$ in a triangle according to $MX$ and $MZ$, A,B,C ?

Do I have to find the normal ?

I have the coordinates of the points of the triangle

EDIT : I got this formula:

float calcY(Vector3 p1, Vector3 p2, Vector3 p3, float x, float z) {
  float a = -(p3.Z*p2.Y-p1.Z*p2.Y-p3.Z*p1.Y+
              p1.Y*p2.Z+p3.Y*p1.Z-p2.Z*p3.Y);    
  float b = (p1.Z*p3.X+p2.Z*p1.X+p3.Z*p2.X-
             p2.Z*p3.X-p1.Z*p2.X-p3.Z*p1.X);    
  float c = (p2.Y*p3.X+p1.Y*p2.X+p3.Y*p1.X-
             p1.Y*p3.X-p2.Y*p1.X-p2.X*p3.Y);
  float d = -a*p1.X-b*p1.Y-c*p1.Z;
  return -(a*x+c*z+d)/b;    
}

when dividing by zero the triangle is parallel to Y so not 1 solution

1

There are 1 best solutions below

0
On

Given the three vertex $A,B,C$ of the triangle, find the vectors $\vec{AB}$ and $\vec{AC}$, then the vector product $\vec{AB}\times\vec{AC}$ gives the normal to the plane. So you can find the equation of the plane passing thorough $A$ and with this normal. Than it's easy to find the $y$ coordinate of a point $M$ that is in the plane and of given $x_M$ and $z_M$.