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)
… 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

