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 )

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 );
var angle_in_radians = a.angleTo(b);
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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With