假設您有點ABC和Az == Bz,z表示垂直方向。
首先,項目中的X,C的y座標上在2D A和B之間的界線:
// find normalized AB vector:
AB.x = B.x - A.x;
AB.y = B.y - A.y;
length = sqrt(AB.x * AB.x + AB.y * AB.y);
// test for length == 0 to avoid div by zero
AB.x /= length;
AB.y /= length; // note: you could save a division by dividing dot by length instead
// project C onto AB:
AC.x = C.x - A.x;
AC.y = C.y - A.y;
// this gives us how far along the line AB the projected point is:
dot = (AC.x * AB.x) * (AC.y * AB.y);
newC.x = A.x + (AB.x * dot);
newC.y = A.y + (AB.y * dot);
newC.z = A.z; // same as B.z
接着找到投影點和C之間的3D距離,這將是垂直高度的新點的AB線的上方,如果三角形被旋轉到使用AB爲鉸鏈的垂直位置:
newCC.x = C.x - newC.x;
newCC.y = C.y - newC.y;
newCC.z = C.z - newC.z;
height = sqrt((newCC.x * newCC.x) + (newCC.y * newCC.y) + (newCC.z * newCC.z));
設置Z值:
newC.z += height;
非常感謝samgak :) –