在从 3d 空间中的另一个点投影的线上查找点的 3d 坐标 [英] Find 3d coordinates of a point on a line projected from another point in 3d space
本文介绍了在从 3d 空间中的另一个点投影的线上查找点的 3d 坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Swift、ARTKit/SceneKit
Working in Swift, ARTKit / SceneKit
我在 3d 中有一条线 AB,我有 A 点和 B 点的 xyz 坐标.我也有一个 C 点,我也知道它的 xyz 坐标.
I have a line AB in 3d and I have xyz coordinates of both points A and B. I also have a point C and I know its xyz coordinates too.
现在,我想在AB线上找出D点的xyz坐标;假设 CD 垂直于 AB.
Now, I want to find out the xyz coordinates of point D on line AB; given that CD is perpendicular to AB.
在 Swift 中执行此操作的简单方法是什么.
What would be a simple way to do it in Swift.
推荐答案
用标量 t
参数化 AB
行:
Parameterize the line AB
with a scalar t
:
P(t) = A + (B - A) * t`
点D = P(t)
使得CD
垂直于AB
,即它们的点积为零:>
The point D = P(t)
is such that CD
is perpendicular to AB
, i.e. their dot product is zero:
dot(C - D, B - A) = 0
dot(C - A - (B - A) * t, B - A) = 0
dot(C - A, B - A) = t * dot(B - A, B - A)
// Substitute value of t
--> D = A + (B - A) * dot(C - A, B - A) / dot(B - A, B - A)
Swift 代码:
var BmA = B - A
var CmA = C - A
var t = dot(CmA, BmA) / dot(BmA, BmA)
var D = A + BmA * t;
这篇关于在从 3d 空间中的另一个点投影的线上查找点的 3d 坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文