在3D空间中从另一点投影的线上找到点的3D坐标 [英] Find 3d coordinates of a point on a line projected from another point in 3d space

查看:190
本文介绍了在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

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)

快速代码:

var BmA = B - A
var CmA = C - A
var t = dot(CmA, BmA) / dot(BmA, BmA)
var D = A + BmA * t;

这篇关于在3D空间中从另一点投影的线上找到点的3D坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆