If you want an angle a line makes with line 0 (line 0 being straight along the positive z axis) in 3d space, it's probably better to consider 2 angles - the first angle being the horizontal angle, from 0 to 360 degrees in the horizontal plane, and the second being the vertical angle - the angle the line makes with the horizontal plane.
This is a bit like the system used for describing the location of stars - (ie. right acsention and declination - like the horizontal and the vertical angles).
The reason it's better to have two angles is because there are an infinite number of lines in 3d space that would all share the same single angle from line 0. (They would form a cone shape around line 0)
So, if the 3d line is the line joining two objects a and b, then -
Horizontal angle (0 to 360 degrees):
hor_angle#=atanfull(object position x (b)-object position x (a),object position z (b)-object position z (a))
if hor_angle#<0 then hor_angle#=hor_angle#+360
Vertical angle (+90 is straight up, 0 is horizontal and -90 is straight down):
ver_angle#=90-atanfull(sqrt((object position x(b)-object position x(a))^2+(object position z(b)-object position z(a))^2),object position y (b)-object position y (a))
A little demo to see it working:
sync on
autocam off
position camera 0,4,-20
make matrix 1,100,100,10,10
position matrix 1,-50,0,-50
make object sphere 1,1
make object sphere 2,1
a=1
b=2
do
if upkey()=1 then z#=z#+0.1
if downkey()=1 then z#=z#-0.1
if leftkey()=1 then x#=x#-0.1
if rightkey()=1 then x#=x#+0.1
if inkey$()="z" then y#=y#-0.1
if inkey$()="a" then y#=y#+0.1
gosub get_angles
position object 2,x#,y#,z#
line object screen x(a),object screen y(a),object screen x(b),object screen y(b)
text 0,0,"Horizontal angle: "+str$(hor_angle#)
text 0,20,"Vertical angle: "+str$(ver_angle#)
text 0,40,"Use arrow keys to move in horizontal plane."
text 0,60,"Use a and z to move vertically"
sync
loop
get_angles:
hor_angle#=atanfull(object position x (b)-object position x (a),object position z (b)-object position z (a))
if hor_angle#<0 then hor_angle#=hor_angle#+360
ver_angle#=90-atanfull(sqrt((object position x(b)-object position x(a))^2+(object position z(b)-object position z(a))^2),object position y (b)-object position y (a))
return
