08-04-2004, 03:47 AM
OK... so I have this sub to find the angles between two points in 3D space... note that theta and phi are the output variables that contain the two angles.
[syntax="qbasic"]SUB angle (x1, y1, z1, x2, y2, z2, theta AS INTEGER, phi AS INTEGER)
x = x1 - x2
y = y1 - y2
z = z1 - z2
d = SQR(x ^ 2 + y ^ 2)
IF x <> 0 THEN
theta = ATN(y / x) / (pi! / 180)
END IF
IF d <> 0 THEN
phi = ATN(z / d) / (pi! / 180)
END IF
END SUB[/syntax]
..But sometimes, it doesn't work correctly. When the angle for theta should be 91, it becomes 271. Can anyone help?
[syntax="qbasic"]SUB angle (x1, y1, z1, x2, y2, z2, theta AS INTEGER, phi AS INTEGER)
x = x1 - x2
y = y1 - y2
z = z1 - z2
d = SQR(x ^ 2 + y ^ 2)
IF x <> 0 THEN
theta = ATN(y / x) / (pi! / 180)
END IF
IF d <> 0 THEN
phi = ATN(z / d) / (pi! / 180)
END IF
END SUB[/syntax]
..But sometimes, it doesn't work correctly. When the angle for theta should be 91, it becomes 271. Can anyone help?