I'm trying to program a one-axis N-S solar tracker for my Photovoltaic Array.
The array tilts only on the y-axis, so in order to get the optimum angle independent from the season I need to calculate the angle that the sun position would project into an x-z plane. In that case the angle of the vector (0,0)(x,z).
const x = radius * Math.cos(elevation) * Math.sin(azimuth);
const y = radius * Math.cos(elevation) * Math.cos(azimuth);
const z = radius * Math.sin(elevation);
I've tried to apply the above formulas to convert the sun's position to cartesian coordinates, and it should plot the Sun travel as a curve, but as you can see it is failing.
If that worked, I would need to get the Q angle. Can someone help me?


So the solution was so simple as to feed the Azimuth and Elevation angles in radians. I was feeding them in degrees. (DOH)