Do use an array such as p[0],p[1],p[2]
for a point, but
to keep things straight, follow the suggestion above
by defining x,y,z
to be coordinates indices 0,1,2, rather than
the actual coordinate values, so that you can say p[x],p[y],p[z]
when you wish but also do loops with p[i]
other times. Since this
is the basic level, you might not use functions. Your program
might look something like the following. Examine carefully how
the matrix multiplication goes; think it through to see how it
does correspond to what you do when you multiply matrices by hand.
// (some or all of these include files may not be needed, depending
// on the compiler)
#include <math.h>
#include <stream.h>
#include <fstream.h>
#include <stdlib.h>
const int x = 0;
const int y = 1;
const int z = 2;
const double pi = ...;
void main(int argc, char** argv)
{
// -------------- get args, convert to radians -----------
double view_lat_deg = (argc>1) ? atof(argv[1]) : 0.0;
double view_long_deg = (argc>2) ? atof(argv[2]) : 0.0;
double view_lat_rad = ...;
double view_long_rad = ...;
// ----- find rotation R taking viewplane to north pole ------
double rot_long[3][3];
double rot_lat[3][3];
rot_long[x][x] = rot_long[y][y] = cos(view_long_rad + pi/2);
rot_long[x][y] = ...;
//etc. to complete rot_long
rot_lat[x][x] = ...
//etc. to complete rot_lat
double R[3][3];
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
{
R[i][j] = 0.0;
for (int k=0; k<3; k++)
R[i][j] += rot_long[i][k]*rot_lat[k][j];
}
// ------------------------------ draw circle -----------------
for (int i=0; i<=60; i++)
{
double t = 2*pi*i/60.; // better use 60., not 60 (why?)
cout << ... // write out cos(t), space, sin(t)
}
cout << endl;
// ------------------------------ main loop -------------------
int connect;
double data_lat_deg, data_long_deg;
double data_lat_rad, data_long_rad;
double data_pt[3];
double p[3];
// -------------- read in data, convert to Euclidean -----
(open stream fin to read continents file)
if (!fin)
{
cerr << "can't open continents file for reading" << endl;
exit(-1);
}
while ( fin >> connect >> data_lat_deg >> data_long_deg )
{
// convert to data_lat_rad, data_long_rad in radians;
/ expressions on right will involve sines, cosines
data_pt[x] = ...
data_pt[y] = ...
data_pt[z] = ...
// rotate the data point: p = data_pt * R
for (int j=0; j<3; j++)
{ // call outer index j since entry of row vector is column
p[j] = 0.0;
for (int i=0; i<3; i++)
p[j] += data_pt[i]*R[i][j];
}
// ------------ check visibility, etc. ------------------
// (see earlier part of this handout)
}
}
Even if you intend to work at the 10A level, please read the next part.