Cartesian to polar conversion
From Programming In C
[edit]
Exercise 6.1
The Vectors Data File link points to a data file which contains a (unspecified) number of position vectors in the form (x,y,z). Save this file on your U: drive via:
- Open the link, copy and paste this data into a Word or Notepad document called vectors in the same directory as your source code. Save the file as ”Text only”, so that it will be called vectors.txt.
Write a program that opens the file vectors.txt and for each vector (x,y,z) calculates the spherical polar co-ordinates (r;,θ,φ) and writes these values out to a file called spher.txt. Spherical polar co-ordinates are defined in the image below (image courtesy of http://en.citizendium.org):
Note that in this definition of spherical polar co-ordinates φ lies in the range -π to +π (which means you must use atan2) and θ lies in the range 0 to +π.

