Skip to content

Commit

Permalink
Better precision for Tl2ec and Tec2l computations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Aug 24, 2020
1 parent 94fef95 commit 679bda6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/models/FGInertial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ bool FGInertial::Run(bool Holding)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FGMatrix33 FGInertial::GetTl2ec(FGLocation& location) const
FGMatrix33 FGInertial::GetTl2ec(const FGLocation& location) const
{
FGColumnVector3 North, Down, East{-location.GetSinLongitude(),
location.GetCosLongitude(), 0.};
FGColumnVector3 North, Down, East{-location(eY), location(eX), 0.};

switch (gravType) {
case gtStandard:
Expand All @@ -151,9 +150,15 @@ FGMatrix33 FGInertial::GetTl2ec(FGLocation& location) const
}
break;
case gtWGS84:
Down = GetGravityJ2(location);
}
{
FGLocation sea_level = location;
sea_level.SetPositionGeodetic(location.GetLongitude(),
location.GetGeodLatitudeRad(), 0.0);
Down = GetGravityJ2(location);
Down -= vOmegaPlanet*(vOmegaPlanet*sea_level);}
}
Down.Normalize();
East.Normalize();
North = East*Down;

return FGMatrix33{North(eX), East(eX), Down(eX),
Expand Down
4 changes: 2 additions & 2 deletions src/models/FGInertial.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class FGInertial : public FGModel {
@return a rotation matrix of the transform from the earth centered frame
to the local horizontal frame.
*/
FGMatrix33 GetTl2ec(FGLocation& location) const;
FGMatrix33 GetTl2ec(const FGLocation& location) const;

/** Transform matrix from the earth centered to local horizontal frame.
The local frame is the NED (North-East-Down) frame. Since the Down
Expand All @@ -175,7 +175,7 @@ class FGInertial : public FGModel {
@return a rotation matrix of the transform from the earth centered frame
to the local horizontal frame.
*/
FGMatrix33 GetTec2l(FGLocation& location) const
FGMatrix33 GetTec2l(const FGLocation& location) const
{ return GetTl2ec(location).Transposed(); }

struct Inputs {
Expand Down
51 changes: 43 additions & 8 deletions tests/unit_tests/FGInertialTest.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <limits>
#include <cxxtest/TestSuite.h>

#include <FGFDMExec.h>
Expand All @@ -7,7 +6,7 @@

using namespace JSBSim;

const double epsilon = 100. * std::numeric_limits<double>::epsilon();
const double epsilon = 1e-5;
constexpr double degtorad = M_PI / 180.;

class FGInertialTest : public CxxTest::TestSuite
Expand All @@ -18,16 +17,52 @@ class FGInertialTest : public CxxTest::TestSuite
FGInertial* planet = fdmex.GetInertial();
fdmex.SetPropertyValue("simulation/gravity-model", 0);
FGLocation loc;
FGMatrix33 Tl2ec, Tec2l;
FGMatrix33 Tec2l;
double radius = planet->GetSemimajor();

for(double lon=-180.; lon <= 180.; lon += 30.) {
double longitude = lon * degtorad;
double cosLon = cos(longitude);
double sinLon = sin(longitude);

for(double lat=-90.; lat <= 90.; lat += 30.) {
loc.SetPosition(lon*degtorad, lat*degtorad, radius);
Tl2ec = planet->GetTl2ec(loc);
Tec2l = planet->GetTec2l(loc);
TS_ASSERT_MATRIX_EQUALS(loc.GetTl2ec(), Tl2ec);
TS_ASSERT_MATRIX_EQUALS(loc.GetTec2l(), Tec2l);
double latitude = lat * degtorad;
loc.SetPosition(longitude, latitude, radius);
double cosLat = cos(latitude);
double sinLat = sin(latitude);
Tec2l = { -cosLon*sinLat, -sinLon*sinLat, cosLat,
-sinLon , cosLon , 0.0 ,
-cosLon*cosLat, -sinLon*cosLat, -sinLat };
TS_ASSERT_MATRIX_EQUALS(planet->GetTec2l(loc), Tec2l);
TS_ASSERT_MATRIX_EQUALS(planet->GetTl2ec(loc), Tec2l.Transposed());
}
}
}

void testTransformationMatricesWGS84Earth() {
FGFDMExec fdmex;
FGInertial* planet = fdmex.GetInertial();
fdmex.SetPropertyValue("simulation/gravity-model", 1);
FGLocation loc;
FGMatrix33 Tec2l;

loc.SetEllipse(planet->GetSemimajor(), planet->GetSemiminor());

for(double lat=-90.; lat <= 90.; lat += 30.) {
double latitude = lat * degtorad;
double cosLat = cos(latitude);
double sinLat = sin(latitude);

for(double lon=-180.; lon <= 180.; lon += 30.) {
double longitude = lon * degtorad;
loc.SetPositionGeodetic(longitude, latitude, 0.0);
double cosLon = cos(longitude);
double sinLon = sin(longitude);
Tec2l = { -cosLon*sinLat, -sinLon*sinLat, cosLat,
-sinLon , cosLon , 0.0 ,
-cosLon*cosLat, -sinLon*cosLat, -sinLat };
TS_ASSERT_MATRIX_EQUALS(planet->GetTec2l(loc), Tec2l);
TS_ASSERT_MATRIX_EQUALS(planet->GetTl2ec(loc), Tec2l.Transposed());
}
}
}
Expand Down

0 comments on commit 679bda6

Please sign in to comment.