Standards Forum

 

Login Register    
Converting to Geocentric
Posted: 01 July 2011 09:48 AM  
Newbie
Rank
Total Posts:  25
Joined  2011-06-23

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.

 
Posted: 03 July 2011 05:21 PM   [ # 1 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

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

 
Posted: 05 July 2011 12:26 PM   [ # 2 ]  
Newbie
Rank
Total Posts:  25
Joined  2011-06-23

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

 
Posted: 05 July 2011 12:30 PM   [ # 3 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

Thanks for the clarification… makes sense.
You do need to set the fltHeader fltProjection field to specify how to interpret the vertex coordinates.

 
Posted: 06 July 2011 12:56 PM   [ # 4 ]  
Newbie
Rank
Total Posts:  25
Joined  2011-06-23

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 GeodeticToGeocentricdouble latitudedouble longitudedouble height )
{
    Point result


    
double semiMajorAxis 6378137.0;
    
double flattening 298.257223563;

    
double Geocent_e2 flattening flattening flattening;

    
double Sin_Lat sin(latitude);
    
double Cos_Lat cos(latitude);
    
double Sin2_Lat Sin_Lat Sin_Lat;

    
double Rn semiMajorAxis / (sqrt(Geocent_e2 Sin2_Lat));
    
result.= (Rn height) * Cos_Lat cos(longitude);
    
result.= (Rn height) * Cos_Lat sin(longitude);
    
result.= ((Rn * (Geocent_e2)) + height) * Sin_Lat;

    return 
result;
}

void Transform 
(mgrec *node,Point translate,Matrix3x3m,Vector3axisFloat 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
    
mgrecg1 mgGetChild(node);
    
mgrecwt1frame mgGetNext(g1);
    
mgrecDimensions10  mgGetNext(wt1frame);
    
mgDetach(g1);
    
mgDetach(wt1frame);
    
mgDetach(Dimensions10);
    
mgrecnewNode 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
    
mgrecxformTranslate mgNewRec(fltXmTranslate);
    
mgSetCoord3d(xformTranslate,fltXmTranslateFrom,0,0,0);
    
mgSetCoord3d(xformTranslate,fltXmTranslateDelta,translate.x,translate.y,translate.z);
    
mgAttach(node,xformTranslate);


    
//Rotate
    
mgrecxformRotate mgNewRec (fltXmRotate);
    
mgSetCoord3d (xformRotatefltXmRotateCenter,    000);
    
mgSetAttList (xformRotatefltXmRotateAngleanglemgNULL);
    
mgrecnestedAttrib mgGetAttRec(xformRotate,fltXmRotateAxis,MG_NULL);
    
mgSetAttList (nestedAttrib,
    
fltVectorIaxis->x,
    
fltVectorJaxis->y,
    
fltVectorKaxis->z,
    
mgNULL);
    
mgAppend (nodexformRotate);
}

int main
(int argccharargv[])
{
    
//lat
    
float u 32*PI/180;
    
//lon
    
float i = -126*PI/180;


    
Matrix3x3= 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= new Quat((Matrix3x3*) m);
    
//look at w,v
    
Vector3axis = new Vector3();
    
Float angle 0;
    
m->getAxisAngle(axis,angle);

    
Point result;
    
mgrecdb;
    
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.<< "," << result.<< "," << result.<< endl;
    
    
Transform(db,result,m,axis,angle);
    
mgWriteDb (db);
    
mgCloseDb (db);


    
mgExit();

    return 
0;
 
Posted: 02 August 2011 11:52 AM   [ # 5 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

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?

 
Posted: 09 August 2011 03:33 PM   [ # 6 ]  
Newbie
Rank
Total Posts:  25
Joined  2011-06-23

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