给定 3D 空间中的一条线,我如何找到从它到点的角度? [英] Given a line in 3D space, how do I find the angle from it to a point?

查看:24
本文介绍了给定 3D 空间中的一条线,我如何找到从它到点的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 3D 空间中有两组点.我想画一条穿过两组点中心的线,然后找到从该线到每个点的角度.从那里开始,我将根据两个设置中两个角度的接近程度来匹配两个设置中的点.

我知道如何找到每组点的中心(只是将它们平均在一起)并且我知道如何匹配它们(甚至考虑到它们会环绕的事实),但我不知道如何求从线到点的角度.

基本上我是说我希望所有点都投影到以穿过中心的直线为中心并垂直于该直线的平面上,并且我希望从该直线到该平面上每个点的角度.

我希望我已经说清楚了...我在这方面没有太多正式的培训(有点让我想起几年前大学时的 Diff Eq),所以请问我是否可能误用了术语并让您感到困惑.

我想我可以将任何其他语言的解决方案翻译成对我有用,因为我认为这主要是语言不可知的数学,但我正在使用 Three.JS 所以如果你的解决方案适用于 javascript/Three.JS(这是他们的


在 *three.js* 中,所有计算都可以通过 [`THREE.Vector3`][2] 的操作来完成:

var a = new THREE.Vector3( ... );var b = new THREE.Vector3( ... );a.标准化();b.标准化();var cosAB = a.dot( b );varangle_in_radians = Math.acos(cosAB);


正如下面评论中提到的,在 *three.js* 中有一个操作 **`.angleTo`**,它简化了很多事情:

var angle_in_radians = a.angleTo(b);


如果你有 4 个点 `Pa`、`Pb`、`Pc`、`Pd`,它们定义了从 `Pa` 到 `Pb` 的 2 条线,并形成了 `Pc` 到 `Pd`,那么可以计算这两个向量如下:

var Pa = new THREE.Vector3( ... );var Pb = new THREE.Vector3( ... );var Pc = new THREE.Vector3( ... );var Pd = new THREE.Vector3( ... );var a = new THREE.Vector3();a.copy(Pb).sub(Pa);var b = new THREE.Vector3();a.copy(Pd).sub(PC);

I have two sets of points in 3D space. I'd like to draw a line that runs through the center of both sets of points, and then find the angle from that line to each point. From there, I'll match points in the two sets up based on how close together their two angles are.

I know how to find the center of each set of points (just average them all together) and I know how to match them up (even accounting for the fact they'll wrap around), but I don't know how to find the angle from the line to the point.

Basically I'm saying I want all the points projected onto a plane that is centered on and perpendicular to the line running through the centers, and I want the angles from that line to each point on that plane.

I hope I've made myself clear... I don't have much formal training in this stuff (kind of reminds me of Diff Eq from college several years ago), so do ask if I've maybe misused a term and confused you.

I figure I can translate a solution from any other language to work for me since I assume this is mostly just language agnostic math, but I'm working with Three.JS so if your solution works in javascript/with Three.JS (here's their Vector3 class documentation, just so you know what helper functions it provides) that'd be most helpful. Thanks!

解决方案

In general The dot product of 2 vectors is equal the cosine of the angle between the 2 vectors multiplied by the magnitude (length) of both vectors.

dot( A, B ) == | A | * | B | * cos( angle_A_B ) 

This follows, that the dot product of 2 unit vectors is equal the cosine of the angle between the 2 vectors, because the length of a unit vector is 1.

uA = normalize( A )
uB = normalize( B )
cos( angle_A_B ) == dot( uA, uB )


In *three.js* all the calculations can be done by the operations of a [`THREE.Vector3`][2]:

var a = new THREE.Vector3( ... );
var b = new THREE.Vector3( ... );

a.normalize();
b.normalize();

var cosAB = a.dot( b );
var angle_in_radians = Math.acos( cosAB );


As mentioned in the comment below, in *three.js* there is an operation **`.angleTo`**, which simplifies the things a lot:

var angle_in_radians = a.angleTo(b);


If you have 4 points `Pa`, `Pb`, `Pc`, `Pd`, which define 2 lines from `Pa` to `Pb` and form `Pc` to `Pd`, then the 2 vectors can be calculated as follows:

var Pa = new THREE.Vector3( ... );
var Pb = new THREE.Vector3( ... );
var Pc = new THREE.Vector3( ... );
var Pd = new THREE.Vector3( ... );

var a = new THREE.Vector3();
a.copy( Pb ).sub( Pa );

var b = new THREE.Vector3();
a.copy( Pd ).sub( Pc );

这篇关于给定 3D 空间中的一条线,我如何找到从它到点的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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