Cartesian to polar conversion

From Programming In C

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:

  1. 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 +π.


Image:SphPolar.png


Next exercise

Return to the course summary

phy225: Course Details

general


compilers


2011-12 assessments


past exam papers

  • 2008-9 (http://physics-database.group.shef.ac.uk/exampapers/2008-09/PHY225%20LT.pdf)
  • 2009-10 (http://physics-database.group.shef.ac.uk/exampapers/2009-10/PHY225%20Exam%20Sem%201%202009-10.pdf)
  • 2010-11 (http://physics-database.group.shef.ac.uk/exampapers/2010-11/PHY225_10_11.pdf)