←Previous Entry | Next Entry→ | |||
Went to see the wonderful dentist Dr. Clapper yesterday. The poor fellow thought he was just going to give me a crown and ended up doing a root canal to boot. Yow! Still, he is a paragon of doctorly expertise. I am a much happier fellow for having a great dentist!
To scale the clipping window, you need the maximum elevation for the vertical scale—which is easy enough to obtain, but for the horizontal scale, it might be useful to use the same unit of measure as the vertical scale. Since we’re at an latitude of about 33.8 degrees, we are at a distance 6370*cos(33.8) = 5290km from the axis of rotation. So the arclength along the circle of rotation is (117-116.5)*5290/360 = 7340 meters.
Well, this thing has eaten up a lot of time, so I don’t want to explain it in much detail other than to show the code and some cross-sections.
The code allows my to choose one of 21 different
longitudinal (west-east) cross-sections such as the two below:
Here’s the code:
/* Draw a cross section of
#include <GL/glut.h> // This includes gl.h and glu.h
float west = 117.0, east = 116.5, north = 33.917, south = 33.75;
// float
mtSJ[21][60] = {{811,796,783,786,795,769,767,764,756,738,740,725,716,704,686,681,670,654,670,623,602,588,572,564,562,554, {792,786,766,797,783,799,759,763,758,740,728,715,700,690,673,680,670,655,675,670,714,617,562,545,536,522,510,499,484,475,461,447,440,511,445, {742,784,756,776,782,782,754,793,880,769,733,709,697,696,840,842,952,861,774,790,739,734,807,606,522,509,498,492,497,470,464,492,460,672,618,633, {715,698,759,789,757,753,738,730,743,813,776,772,772,829,971,1021,1050,980,921,948,953,975,886,843,730,663,717,938,747,555,542,760,777,833,1064,967, {676,664,717,728,687,747,729,681,750,732,742,780,898,1000,1119,1168,1183,1197,1135,1276,1215,1040,951,913,876,921,1058,1347,1047,923,718,960,1209, {669,655,698,758,691,657,701,661,693,711,803,892,945,1028,1219,1189,1190,1330,1292,1212,1190,1176,1049,1078,996,1032,1058,1097,1196,1180,1066,1019 {698,656,648,670,679,612,624,631,637,749,871,945,970,939,1015,1080,1156,1273,1306,1266,1226,1197,1206,1144,1090,1060,1086,1114,1248,1577,1457,1659, {682,585,597,603,607,601,638,649,644,675,819,792,875,943,1088,1165,1157,1168,1207,1214,1290,1258,1227,1214,1170,1162,1174,1216,1366,1574,1762,1902, {575,537,578,603,610,693,811,798,726,718,759,978,1065,1060,1090,1125,1083,1070,1074,1158,1266,1348,1307,1314,1237,1248,1312,1305,1398,1670,1843,2048, {422,542,762,826,850,782,1013,993,856,805,848,998,1051,1071,1088,1139,1010,1093,1143,1206,1317,1508,1456,1441,1373,1346,1345,1475,1527,1804,2076, {427,427,471,716,925,1089,1076,1038,977,987,1003,1026,1043,1071,1076,1124,989,1146,1202,1219,1324,1342,1446,1489,1521,1602,1598,1727,1933,2001,2178, {436,433,434,477,675,804,894,1110,1039,1204,1085,1088,1077,964,1042,978,1045,1169,1153,1129,1169,1177,1289,1345,1479,1632,1754,1947,1968,2324,2174, {430,433,447,443,440,478,668,911,991,100,928,845,96,825,883,874,958,1121,1191,1073,1076,1084,1222,1298,1319,1589,1721,1820,1876,2008,1965,1846,1840, {453,448,450,461,461,454,455,503,717,882,827,824,759,754,766,822,942,1129,1111,1053,983,1046,1109,1212,1331,1491,1743,1667,1804,1864,1793,1798,1859, {456,452,457,465,469,465,463,468,469,564,615,613,628,646,635,659,788,933,1045,966,940,980,1153,1235,1328,1425,1617,1747,1611,1683,1567,1746,1749,2002, {457,456,460,461,474,475,480,485,483,504,565,629,602,591,592,602,718,710,774,840,869,929,1036,1215,1227,1306,1434,1570,1402,1470,1677,1751,1979,2247, {461,464,459,459,470,475,472,472,473,502,523,558,552,542,598,723,727,666,678,741,866,1045,1242,1337,1524,1620,1637,1359,1461,1749,1770,1834,1938, {466,465,466,464,460,471,481,467,481,482,497,520,554,616,634,641,707,656,601,695,775,915,1268,1431,1529,1558,1488,1380,1446,1518,1580,1773,1896, {460,465,471,472,477,480,488,494,499,499,493,502,514,546,584,596,624,582,580,686,799,853,1090,1301,1393,1419,1264,1414,1496,1621,1670,1840,1970, {464,469,473,476,484,485,500,556,530,511,508,498,520,514,520,560,591,613,685,752,815,963,1177,1253,1248,1227,1180,1360,1578,1665,1782,1881,1806,
int maximum(float *a, int n) { float max = a[0]; for (int i = 1; i <= n; ++i) if (a[i] > max) max = a[i]; return max; }
int longitude = 15; // Change this for one of the other cross-sections: 0-20 int m = 60; float maxElevation = maximum(mtSJ[longitude],m); float longitudeLength = (west - east)*5290000.0/360.0;
float abscissa[60]; float increment = longitudeLength/60.; void makeAbscissa() { for (int i = 0; i<60; ++i) abscissa[i] = i*increment; }
void draw_axes() { glColor3f(0.0,0.0,.0); glBegin(GL_LINES); glVertex2f(0.0,-100.); glVertex2f(0.0,maxElevation); glVertex2f(-100.,0.0); glVertex2f(longitudeLength,0.); glVertex2f(-50,maxElevation/2.); glVertex2f(50,maxElevation/2.); glVertex2f(longitudeLength/2.,-50.); glVertex2f(longitudeLength/2.,50.); glEnd(); glBegin(GL_TRIANGLES); // Draw arrow heads glVertex2f(-40.,maxElevation); glVertex2f(40.,maxElevation); glVertex2f(0.,maxElevation+80.); glVertex2f(longitudeLength,40.); glVertex2f(longitudeLength,-40.); glVertex2f(longitudeLength+80,0.); glEnd(); }
void draw_segment(GLfloat ax, GLfloat ay, GLfloat bx, GLfloat by) { glColor3f(0.0,0.0,1.0); glBegin(GL_LINES); glVertex2f(ax, ay); glVertex2f(bx, by); glEnd(); }
void draw_mountain() { glColor3f(0.0,0.0,1.0); for(int i = 0; i<60; ++i) draw_segment(abscissa[i], mtSJ[longitude][i], abscissa[i+1], mtSJ[longitude][i+1]); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); int n = 6; glColor3f(1.0, 0.0, 0.0); makeAbscissa(); glLineWidth(1.0); draw_axes(); glRasterPos2f(100.,maxElevation-40.);// This labels vertical axis glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'E'); glRasterPos2f(100.+120.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'l'); glRasterPos2f(100.+200.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'e'); glRasterPos2f(100.+300.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'v'); glRasterPos2f(100.+400.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'a'); glRasterPos2f(100.+500.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 't'); glRasterPos2f(100.+600.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'i'); glRasterPos2f(100.+700.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'o'); glRasterPos2f(100.+800.,maxElevation-40.); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, 'n'); glLineWidth(3.0); draw_mountain(); glFlush(); }
void init() { //set clear color to white glClearColor(1.0,1.0,1.0,1.0); //set standard orthogonal (look straight at) clipping view glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Scale window gluOrtho2D(-100.0,longitudeLength+100.0,-100.0,maxElevation+100.); } int main(int argc, char** argv) { //init mode and open window in upper-left corner glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_ glutInitWindowSize(400,400); glutInitWindowPosition(0,0); glutCreateWindow("dimple"); glutDisplayFunc(display); init(); glutMainLoop(); }
|