I got two triangles, "starting" from seperate points $P_1$ and $P_2$, but sharing a common base $AB$. I try to get those triangles to form a $90°$ angle at their common base. I'd expect, as long as the triangles don't share the same plane, that I would get one or - in most of the cases - two valid solutions. Is this assumtion correct?
The Task:
Given the points $P_1$, $P_2$, $A$ and $B$, with
$$A = (a_x, a_y, a_z + \Delta z)$$ $$B = (b_x, b_y, b_z + \Delta z)$$
find the value $\Delta z$ so that the triangles $\bigtriangleup P_1AB$ and $\bigtriangleup P_2AB$ are perpendicular.
My Approach:
I started with $\bigtriangleup P_1AB$ and $\bigtriangleup P_2AB$ are perpendicular if the dot-product of their normals is $0$, so:
$$\vec{n_1} \cdot \vec{n_2} = 0$$ $$(\vec{P_1A} \times \vec{AB}) \cdot (\vec{P_2A} \times \vec{AB}) = 0$$
using Lagrange's identity I can get rid of the cross product:
$$(\vec{P_1A} \cdot \vec{P_2A}) * (\vec{AB} \cdot \vec{AB}) - (\vec{AB} \cdot \vec{P_2A}) * (\vec{P_1A} \cdot \vec{AB}) = 0$$
With $(\vec{AB} \cdot \vec{AB}) = |\vec{AB}|²$ I get rid of the $\Delta z$ in that term, since the lenght of the base does not change:
$$|\vec{AB}|² * (\vec{P_1A} \cdot \vec{P_2A}) - (\vec{AB} \cdot \vec{P_2A}) * (\vec{P_1A} \cdot \vec{AB}) = 0$$
$$|\vec{AB}|² * ((a_x - p1_x)*(a_x - p2_x)+(a_y - p1_y)*(a_y - p2_y)+((a_z + \Delta z) - p1_z) * ((a_z + \Delta z) - p2_z)) - ((b_x-a_x)*(a_x - p2_x) + (b_y-a_y)*(a_y - p2_y)+((b_z + \Delta z)-(a_z + \Delta z))*((a_z + \Delta z) - p2_z)) * ((a_x-p1_x)*(b_x-a_x)+(a_y-p1_y)*(b_y-a_y)+((a_z + \Delta z)-p1_z)*((b_z + \Delta z)-(a_z + \Delta z))) = 0$$
Some of the $\Delta z$ cancel each other out, so I got:
$$|\vec{AB}|² * ((a_x - p1_x)*(a_x - p2_x)+(a_y - p1_y)*(a_y - p2_y)+((a_z + \Delta z) - p1_z) * ((a_z + \Delta z) - p2_z)) - ((b_x-a_x)*(a_x - p2_x) + (b_y-a_y)*(a_y - p2_y)+(b_z - a_z)*((a_z + \Delta z) - p2_z)) * ((a_x-p1_x)*(b_x-a_x)+(a_y-p1_y)*(b_y-a_y)+((a_z+\Delta z)-p1_z)*(b_z-a_z)) = 0$$
with $ X = (b_x - a_x), Y = (b_y - a_y), Z = (b_z - a_z) $:
$$|\vec{AB}|² * ((a_x - p1_x)*(a_x - p2_x)+(a_y - p1_y)*(a_y - p2_y)+((a_z + \Delta z) - p1_z) * ((a_z + \Delta z) - p2_z)) - (X*(a_x - p2_x) + Y*(a_y - p2_y)+Z*((a_z + \Delta z) - p2_z)) * (X*(a_x-p1_x)+Y*(a_y-p1_y)+Z*((a_z+\Delta z)-p1_z)) = 0$$
But that's still a rather big term. Is there a way to solve this problem in a more elegant way?