1
0
Fork 0

Working on terrain elevation interpolation routine.

This commit is contained in:
curt 1997-07-10 02:22:10 +00:00
parent be5527975f
commit abf27ac881

View file

@ -155,8 +155,11 @@ void mesh_do_it(struct mesh *m) {
double mesh_altitude(double lon, double lat) { double mesh_altitude(double lon, double lat) {
/* we expect incoming (lon,lat) to be in arcsec for now */ /* we expect incoming (lon,lat) to be in arcsec for now */
double xoffset, yoffset; double xlocal, ylocal, dx, dy;
int x1, y1, z1, x2, y2, z2, x3, y3, z3;
int xindex, yindex; int xindex, yindex;
double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10;
double a, b, c;
/* determine if we are in the lower triangle or the upper triangle /* determine if we are in the lower triangle or the upper triangle
______ ______
@ -165,28 +168,40 @@ double mesh_altitude(double lon, double lat) {
| / | | / |
|/ | |/ |
------ ------
then calculate our end points
*/ */
xoffset = lon - eg.originx; xlocal = ( lon - eg.originx ) / eg.col_step;
yoffset = lat - eg.originy; ylocal = ( lat - eg.originy ) / eg.row_step;
xindex = xoffset / eg.col_step; xindex = (int)xlocal;
yindex = yoffset / eg.row_step; yindex = (int)ylocal;
if ( xindex > yindex ) { dx = xlocal - xindex;
} dy = ylocal - yindex;
if ( (xindex >= 0) && (xindex < eg.cols) ) {
if ( (yindex >= 0) && (yindex < eg.rows) ) { x1 = xindex;
return( eg.mesh_data[xindex * eg.rows + yindex] ); y1 = yindex;
} z1 = eg.mesh_data[x1 * eg.rows + y1];
x2 = xindex + eg.col_step;
y2 = yindex + eg.row_step;
z2 = eg.mesh_data[x2 * eg.rows + y2];
if ( dx > dy ) {
x3 = xindex + eg.col_step;
y3 = yindex;
z3 = eg.mesh_data[x3 * eg.rows + y3];
} else {
x3 = xindex;
y3 = yindex + eg.row_step;
z3 = eg.mesh_data[x3 * eg.rows + y3];
} }
/* /* given (x1, y1, z1) (x2, y2, z2) and (x3, y3, z3) calculate (a,
given (x1, y1, z1) (x2, y2, z2) and (x3, y3, z3) * b, c) such that z = ax + by + c is the equation of the plane
calculate z = ax + by + c (the equation of the plane intersecting the * intersecting the three given points */
three given points
Then, given a position we can calculate the current ground elevation
tmp1 = (x2 * z1 / x1 - z2); tmp1 = (x2 * z1 / x1 - z2);
tmp2 = (y2 - x2 * y1 / x1); tmp2 = (y2 - x2 * y1 / x1);
@ -204,15 +219,26 @@ double mesh_altitude(double lon, double lat) {
b = tmp10 / tmp3; b = tmp10 / tmp3;
c = tmp7; c = tmp7;
*/
/* Then, given a position we can calculate the current ground elevation */
printf("Our true ground elevation is %.2f\n", a*lon + b*lat + c);
if ( (xindex >= 0) && (xindex < eg.cols) ) {
if ( (yindex >= 0) && (yindex < eg.rows) ) {
return( eg.mesh_data[xindex * eg.rows + yindex] );
}
}
} }
/* $Log$ /* $Log$
/* Revision 1.8 1997/07/09 21:31:15 curt /* Revision 1.9 1997/07/10 02:22:10 curt
/* Working on making the ground "hard." /* Working on terrain elevation interpolation routine.
/* /*
* Revision 1.8 1997/07/09 21:31:15 curt
* Working on making the ground "hard."
*
* Revision 1.7 1997/07/08 18:20:13 curt * Revision 1.7 1997/07/08 18:20:13 curt
* Working on establishing a hard ground. * Working on establishing a hard ground.
* *