void LineHelpersTest::testOrtho() { double eps = 0.001; Point2d testP(0, 1); Point2d a(0, 0); Point2d b(2, 0); double res = orthoProject(testP, a, b); QString err = QString("%1, %2").arg(testP.x).arg(res); QVERIFY2(fabs(res) < eps, err.toAscii().data()); testP.x = 1; res = orthoProject(testP, a, b); err = QString("%1, %2").arg(testP.x).arg(res); QVERIFY2(fabs(res - testP.x) < eps, err.toAscii().data()); testP.x = .5; res = orthoProject(testP, a, b); err = QString("%1, %2").arg(testP.x).arg(res); QVERIFY2(fabs(res - testP.x) < eps, err.toAscii().data()); testP.x = 2; res = orthoProject(testP, a, b); err = QString("%1, %2").arg(testP.x).arg(res); QVERIFY2(fabs(res - testP.x) < eps, err.toAscii().data()); testP.x = -1; res = orthoProject(testP, a, b); err = QString("%1, %2").arg(testP.x).arg(res); QVERIFY2(fabs(res - testP.x) < eps, err.toAscii().data()); err = QString("Was %1").arg(orthoProject(b, a, b)); testP = Point2d(1, 0); QVERIFY2(orthoProject(testP, a, b) == 1.0, err.toAscii().data()); QVERIFY(orthoProject(a, a, b) == 0); }
// **************************************************************************************************************************************************** void vec2coord(double x[3], double *sinlati, double *longi) { double greenwich[3] = {1.0, 0.0, 0.0}; double ganges[3] = {0.0, 1.0, 0.0}; double northpole[3] = {0.0, 0.0, 1.0}; double dummy[3] = {x[0], x[1], x[2]}; *sinlati = sin(0.5*pi - angle(northpole, x)); orthoProject(dummy, greenwich, ganges); *longi = angle(greenwich, dummy); if(rightHanded(greenwich,northpole,dummy)) *longi *= -1.0; }