If I have two 3d angles like [120 degrees, 40 degrees]
and [70 degrees, 90 degrees]
, how would I calculate the scaler angle between them? All the related answers I see on here are about vectors with lengths, but I just have angles.
UPDATE:
I wrote this program based on Lewis's answer, but I don't think its right.
var deg = Math.PI/180
var sin = Math.sin, cos = Math.cos, acos = Math.acos, pow = Math.pow
var cpointA = {r:1, a1: 120*deg, a2: 0*deg}
var cpointB = {r:1, a1: 90*deg, a2: 0*deg}
var pointA = cartesianFromSpherical(cpointA)
var pointB = cartesianFromSpherical(cpointB)
function angleBetween(pointA, pointB) {
return acos(dot(pointA,pointB)/(mag(pointA)*mag(pointB)))
}
function dot(a,b) {
return a.x*b.x + a.y*b.y + a.z*b.z
}
function mag(point) {
var x = point.x, y = point.y, z = point.z
return pow(pow(x,2)+pow(y,2)+pow(z,2), .5)
}
function cartesianFromSpherical(sphericalPoint) {
var r = sphericalPoint.r, a1 = sphericalPoint.a1, a2 = sphericalPoint.a2
return {
x: r * sin(a1)*cos(a2),
y: r * sin(a1)*sin(a2),
z: r * cos(a1)
}
}
function radiansFromDeg(xDegrees) {
return xDegrees*deg
}
function degreesFromRad(radians) {
return radians/deg
}
theta = angleBetween(pointA,pointB)
degreesFromRad(theta)
This gives the expected answer of 30 degrees. But if I switch a1 and a2 by changing my points to:
var cpointA = {r:1, a1: 0*deg, a2: 120*deg}
var cpointB = {r:1, a1: 0*deg, a2: 90*deg}
I get 0 degrees. I'd still expect 30 degrees. What am I doing wrong here?
UPDATE:
Lewis helped me understand that my program above is written correctly and I was just misunderstanding the spherical coordinates.