[Math] Triangle in 3D space point X and Y coordinate know find Z

3dgeometrytriangles

I have a triangle in a 3D space. I know the points X an Y coordinate but I dont know the Z. How can the Z be calculated by knowing the points of the triangle and the X an Y coordinate of the point that misses Z.

Example:

Triangle points
(0, 0, 0)
(0, 10, 10)
(10, 20, 10)

Point in triagle
(5, 7, x)

So what is x?

Best Answer

Your numbers don’t work out, since the point turns out to be not in your triangle. I’m guessing that you just chose the points more or less at random, so I’m going to change one of your numbers to make everything work out.

If the triangle points are $P=(0,0,0)$, $Q=(0,10,10)$, and $R=(10,4,10)$ and your point $T$ is $(5,7,x)$, then the general principle is that $T$ is in the triangle $PQR$ if and only if $T=aP+bQ+cR$, with “scalars” $a,b,c$ multiplying the “vectors” $P,Q,R$, and furthermore $a+b+c=1$, and all three scalars being (weakly) between $0$ and $1$.

In this situation, because $P$ is the origin, all the products with $a$ drop out, so you get the three equations \begin{align} 10c&=5\\ 10b+4c&=7\\ 10b+10c&=x\,. \end{align} You easily solve these: $c=1/2$, then from $10b+2=7$ you get $b=1/2$ as well, and consequently $x=10$, your desired result.