How to get the coordinates of the foot of an altitude in a 3D triangle

304 Views Asked by At

I have predefined A,B,V coordinates and I want to find the coordinates for foot of altitude issued from $V$ in triangle $ABV$. All coordinates are 3D. I separated the X,Y and Y,Z planes and applied a 2D equation two times. But I couldnt get the expected result.

This is my try:-

        $numerator = ( pow($x2- $x1,2) + pow($y2-$y1,2) );

        $x= ( ($x2-$x1) * ( $x3*($x2-$x1) + $y3*($y2-$y1) ) + ($y2-$y1) * ($x1*$y2-$x2*$y1) )/ $numerator;

        $y = ( ($y2-$y1) * ( $x3*($x2-$x1) + $y3*($y2-$y1) ) - ($x2-$x1) * ($x1*$y2-$x2*$y1) )/ $numerator;

        $z= ( ($z2-$z1) * ( $z3*($z2-$z1) + $y3*($y2-$y1) ) + ($y2-$y1) * ($z1*$y2-$z2*$y1) )/ ( pow($z2- $z1,2) + pow($y2-$y1,2) );


Here is my output and expectation:- Expectation and behaviour

I have passed A,B and V. My expectation isEx. But the result is C. How do i get the coordinates of my expectation?Thanks in advance and sorry for my bad english.

1

There are 1 best solutions below

2
On BEST ANSWER

I assume that $A=(x_1,y_1,z_1), B=(x_2,y_2,z_2), V=(x_3,y_3,z_3).$

We are looking for the coordinates $(x,y,z)$ of the foot $Ex$ of the altitude issued from $V$ in triangle $ABV$.

The formulas you need are, in a first step :

$$w=\dfrac{(x_1 - x_2)(x_3 - x_2) + (y_1 - y_2)(y_3 - y_2) + (z_1 - z_2)(z_3 - z_2)}{(x_1 - x_2)^2 + (y_1 - y_2)^2 + (z_1 - z_2)^2}\tag{1}$$

In a second step, with this value of $w$ :

$$M=Ex\begin{cases}x=x_2+w(x_2-x_1)\\y=y_2+w(y_2-y_1)\\z=z_2+w(z_2-z_1)\\\end{cases}\tag{2}$$

Explanations of (1) and (2) using vector computations :

The general point $M$ on line $AB$ is such that :

$$\vec{VM}=\vec{VB}+w\vec{BA} \tag{3}$$

(do you see the similitude with formula (2) ?).

Condition $VM \perp AB$ can be written as a zero dot product

$$\vec{VM}.\vec{AB}=0 \tag{4}.$$

Substituting (3) in (4), we get :

$$\vec{VB}.\vec{AB}-w \vec{AB}.\vec{AB}=0$$

giving equivalently :

$$w=\dfrac{\vec{VB}.\vec{AB}}{\vec{AB}^2}$$

which is formula (1).