next up previous
Next: t_see_world Up: t_see_world Previous: t_see_world

1. More details of your program

Let's assume you use C++ and call your program seeworld.cpp . Also, since in C++ the coordinates of a point p are p[0],p[1],p[2], for clarity define x to be 0, y to be 1, and z to be 2, so you can write p[x],p[y],p[z] for the three coordinates. (But this means you can't use x,y,z later for other things!)

  1. Output the points of a unit circle. Specifically, make a loop with a variable (say i) going from 0 to 60 (say), use it to have a variable t go from 0 to 2*pi in 60 steps, and for each value of t, output cos(t) and sin(t) on one line. Don't omit the point where i is $ 60$.

  2. Get viewing latitude and longitude from command-line arguments, as described in Section [*] below; convert to radians.

  3. Make a suitable rotation matrix R taking the viewpoint to infinity on the $ z$-axis. Specifically, $ R = R_{long+\pi/2}^{y \rightarrow x}
R_{\pi/2-lat}^{z \rightarrow y}$.

  4. For each data line:
    1. Read data, checking for end of file. (The discussion here assumes you have opened H:\class\m149.1\continents.dat as a named file.)

    2. Convert angle data to radians.

    3. Convert data points to Cartesian coordinates in three dimensions, treating the world as a sphere of radius 1. Specifically, for a point of latitude $ \theta$ and longitude $ \phi$, Cartesian coordinates are $ (\cos\theta \cos\phi, \cos\theta \sin\phi, \sin\theta )$.

    4. Transform by R to get coordinates (say) p[x], p[y], p[z].

    5. If the point p is visible from above (i.e., if p[z] > 0) then
      1. If the previous point was hidden or p is not connected to it, write a blank line.

      2. cout << p[x] << " " << p[y] << endl;

      (If p is hidden, do nothing. If you use nested if...else{}'s, remember that C and C++ associate the else with the most recent if unless you used { } blocks.)

    6. Save information about visibility of p, to use for the next point. (Before starting the read-data loop, you'll need to set this information to ``hidden'' for use by the first data point. Otherwise the first data point will be plotted connected to the circle!)


next up previous
Next: t_see_world Up: t_see_world Previous: t_see_world
Kirby A. Baker 2002-02-21