Home >> Programming Projects >> How to Turn Altitude and Azimuth into a Vector

How to Turn Altitude and Azimuth into a Vector

I recently needed to find the math required to turn altitude and azimuth angles into a vector so that I could do rotation transformations in Sketchup based off of them. (The plugin I wrote with this is here if you're interested.)

 A quick Google search yielded nothing I could use, so I had to take the time to sit down and figure it out. It's not too terrible complicated if you're good at trig, but it does take a few minutes out of your day which could be spent on other things.  

The Math for Turning Altitude and Azimuth into a Vector

Here we go...

z = sin(altitude)
hyp = cos(altitude)
y = hyp*cos(azimuth)
x = hyp*sin(azimuth)
vector = (x,y,z)

Note: The magnitude part of the vector is assumed to be 1 here so that it disappears. We are only concerned with the direction part of the vector.

... and that's all there is to it.

The Sketchup Ruby Code for Turning Altitude and Azimuth into a Vector

Here is the Ruby code for turning the altitude and azimuth into a vector. It is designed to run inside of Sketchup and uses its API in a couple of spots. The ".degrees" and " Geom::Vector3d.new" will only work inside of Sketchup, so you will have to change them if you aren't using it.

def alt_az_to_vector(altitude,azimuth)
    z  = Math.sin(altitude.degrees)
    hyp = Math.cos(altitude.degrees)
    y = hyp*Math.cos(azimuth.degrees)
    x = hyp*Math.sin(azimuth.degrees)
    return new_vector = Geom::Vector3d.new(x,y,z)
end


 

 

 

 

 

 

 

 

 

 

 

 

 

 

Home >> Programming Projects >> How to Turn Altitude and Azimuth into a Vector