Conversion of spherical coordinates to cartesian coordinates code Heliostat

Hi,

Could someone please explain the below code to me. This is part of a heliostat code written by Jremington. Why do we have '*' before ele and az (which stands for elevation and azimuth)

Basically, I am trying to understand the code for the conversion of spherical coordinates to cartesian coordinates

void xyz_to_eleAz(float * ele, float * az, float xyz[3]){
  float rtd = 180.0 / PI;
  
  float v[3], m = 0;
  // normalize input vector
  for (byte i = 0; i < 3; i++)
    m = m + (xyz[i] * xyz[i]);
    m = sqrt(m);
  
  for (byte i = 0; i < 3; i++) 
   v[i] = xyz[i] / m;
   float t = rtd * atan2(v[0], v[1]);
     if (t < 0.0) {
        t = t + 360.0; //compass wrap
      }
  *az = t;
  *ele = rtd * asin(v[2]);

If anyone could also suggest the formula or code required to write create the conversion. Why are we normalising the data?

To dereference the pointers.
To return the values to the caller

Applying the IDE's auto format tool to the code would make the code easier to understand and visualise

You could ask @jremington !

Your requests for explanation are coming across really badly as excuses for plagiarism.

Dereferencing was explained on your other topic about this code.

It's the same as your earlier post.

You need learn about arrays, pointers, dereferencing and call by reference.

Srsly, you don't want to have to come here every time a little bit of C/C++ is outside your experience.

You'll get tired of that. So might we. :expressionless:

a7

@sroy10 Do not cross post.

Why are we normalising the data?

Very basic trigonometry: look up the concepts of "unit circle" and "unit sphere".

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.