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

查看:104
本文介绍了给定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.normalize();b.normalize();var cosAB = a.dot(b);var angle_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"的形式,则可以计算2个向量如下:

  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天全站免登陆