Start a new topic

Converting to Geocentric

Original Post by: jrhea Fri Jul 1 14:48:35 2011


Ok so I have inserted a new group node into my scene graph just under the header. I added two transform nodes to this new group node: fltXmTranslate and fltXmRotate. Do I need to change the Projection Type from Flat Earth to Geocentric on the header record? Are there any other 'gotchas' that I should consider? Thanks in advance.


Original Post by: SteveThompson Sun Jul 3 22:21:00 2011


Sorry... it's not clear what you are asking... can you provide more information on what you are trying to do? Thanks

Original Post by: jrhea Tue Jul 5 17:26:33 2011


Sorry I was unclear. What I am trying to do is take a flt file that is in local coordinates and convert it to geocentric coordinates. I attempted to do this by creating a new group node just under the header record and attaching the rest of the scene graph to this new group node. I then add transforms to this new group node so that it is in geocentric coordinates. I was wondering if it was necessary to set the fltProjectionType record to Geocentric now that I have done this. I hope this is a better explanation. thanks

Original Post by: SteveThompson Tue Jul 5 17:30:57 2011


Thanks for the clarification... makes sense.

You do need to set the fltHeader fltProjection field to specify how to interpret the vertex coordinates.

Original Post by: jrhea Wed Jul 6 17:56:07 2011


Thanks for the reply.


I am still having problems with the conversion from a local coordinate system to Geocentric. To recap what I have done so far:


• I converted from Geodetic to Geocentric coordinates

• I calculated the axis and angle to perform the rotation (ENU to Geocentric)

• I altered the existing scene graph by adding a new group node just under the header record and attached the rest of the scene graph to this new group node. Then I added the translation and rotation transformations to this new group node.

• I changed the Projection Type of the header record to Geocentric


The translation seems to work fine. The object in the flt file is appearing at the correct location. The problem is that the object seems to be rotated wrong. To troubleshoot, I created a separate file that had no rotation so it just used the identity matrix. The interesting this was that the object appeared exactly the same as when I had a rotation added. Since I cannot change the rotation, this makes me think that I am altering the scene graph incorrectly. I am attaching the code below. Can you (or anyone) tell me if there is something I am doing wrong? I appreciate the help.


struct Point

{

double x;

double y;

double z;

};


//Converts from geodetic to geocentric (lat,lon in radians)

Point GeodeticToGeocentric( double latitude, double longitude, double height )

{

Point result;


double semiMajorAxis = 6378137.0;

double flattening = 1 / 298.257223563;


double Geocent_e2 = 2 * flattening - flattening * flattening;


double Sin_Lat = sin(latitude);

double Cos_Lat = cos(latitude);

double Sin2_Lat = Sin_Lat * Sin_Lat;


double Rn = semiMajorAxis / (sqrt(1 - Geocent_e2 * Sin2_Lat));

result.x = (Rn + height) * Cos_Lat * cos(longitude);

result.y = (Rn + height) * Cos_Lat * sin(longitude);

result.z = ((Rn * (1 - Geocent_e2)) + height) * Sin_Lat;


return result;

}


void Transform (mgrec *node,Point translate,Matrix3x3* m,Vector3* axis, Float angle )

{

//Alter the scene graph to add a new group node just below the header record and the

//rest of the graph attached to this new group node

mgrec* g1 = mgGetChild(node);

mgrec* wt1frame = mgGetNext(g1);

mgrec* Dimensions10 = mgGetNext(wt1frame);

mgDetach(g1);

mgDetach(wt1frame);

mgDetach(Dimensions10);

mgrec* newNode = mgNewRec(fltGroup);

mgAttach(node,newNode);

mgAttach(newNode,g1);

mgAppend(newNode,wt1frame);

mgAppend(newNode,Dimensions10);



//Set Header - change projection type to Geocentric

mgSetAttList(node,fltProjection,6,MG_NULL);


//get the newly created group node

node = mgGetChild(node);


//Add the following transformations to this new group node

//Translate

mgrec* xformTranslate = mgNewRec(fltXmTranslate);

mgSetCoord3d(xformTranslate,fltXmTranslateFrom,0,0,0);

mgSetCoord3d(xformTranslate,fltXmTranslateDelta,translate.x,translate.y,translate.z);

mgAttach(node,xformTranslate);


//Rotate

mgrec* xformRotate = mgNewRec (fltXmRotate);

mgSetCoord3d (xformRotate, fltXmRotateCenter, 0, 0, 0);

mgSetAttList (xformRotate, fltXmRotateAngle, angle, mgNULL);

mgrec* nestedAttrib = mgGetAttRec(xformRotate,fltXmRotateAxis,MG_NULL);

mgSetAttList (nestedAttrib,

fltVectorI, axis->x,

fltVectorJ, axis->y,

fltVectorK, axis->z,

mgNULL);

mgAppend (node, xformRotate);

}


int main(int argc, char* argv[])

{

//lat

float u = 32*PI/180;

//lon

float i = -126*PI/180;


Matrix3x3* m = new Matrix3x3();


//ENU

m->row[0].set(-sin(i),cos(i),0);

m->row[1].set(-sin(u)*cos(i),-sin(u)*sin(i),cos(u));

m->row[2].set(cos(u)*cos(i),cos(u)*sin(i),sin(u));

Quat* q = new Quat((Matrix3x3*) m);

//look at w,v

Vector3* axis = new Vector3();

Float angle = 0;

m->getAxisAngle(axis,angle);


Point result;

mgrec* db;

char idname[80];

char *id = idname;


mgInit(&argc;, argv);


if (!(db = mgOpenDb(argv[1])))

{

printf("\nError in mgOpenDb(%s)\n", argv[1]);

exit(1);

}


result = GeodeticToGeocentric(u,i,0);

cout<<"Calculated coordinates (x,y,z): " << result.x << "," << result.y << "," << result.z << endl;

Transform(db,result,m,axis,angle);

mgWriteDb (db);

mgCloseDb (db);


mgExit();


return 0;

}

Original Post by: SteveThompson Tue Aug 2 16:52:59 2011


Focusing first on your Transform function... the code there looks reasonable. I copied snippets from it and verified it was working correctly in Creator 4.2.


Have you tried to load the file and debug the values in the rotation xform to make sure they are correct on re-read?


Obvious, but have to make sure... The fltXmRotate angle is degrees, not radians.


The interesting this was that the object appeared exactly the same as when I had a rotation added.

Are you looking at it in Creator or some other viz app?

Original Post by: jrhea Tue Aug 9 20:33:11 2011


I had a problem with my rotation matrix. I was using NED instead of ENU. Thanks

Login to post a comment