Heliostat Code Explaination


I've found this bit of code from a heliostat project currently on GitHub by jremington and am having trouble understanding a bit of code from there.

Essentially, it gets the azimuth and altitude and converts that in x y z coordinates and vice versa.

Could someone please explain to me *symbol before xyz++ means and the code written



@jremington might stop by and explain the code.

In the meantime, go learn about arrays, pointers and call by reference to up your C/C++ game.


The "*" is a pointer, meaning the "address of" the named field. So *xyz means the address or location of xyz.

Pointer dereference.

That line of code stores the result of the calculation in the location pointed to by "xyz", then increments the pointer xyz.

Great thank you very much.

Why are you incrementing xyz by 1 in your altAz to xyz code?

To point to the next location in the array (four bytes away for a float).

You need to read up on pointer arithmetic.

Thanks will do!

I have another question: I understand that you are passing an array xyz[3] to that function. So where are the values of x, y and z getting stored? or are they not stored.

Take a look at the rest of the code, so you can see how the function is used.

The calling program allocates an array, and passes a pointer to the array in the function call argument list. The function stores the calculated values in the array locations indexed by the pointer.

The function could also be written as:

  xyz[0] = cos(alt * dtr) * sin(az * dtr);
  xyz[1] = cos(alt * dtr) * cos(az * dtr);
  xyz[2] = sin(alt * dtr);

Please post code using code tags, not pictures of code.