def testOffset(self): """Test offset, angularSeparation and orientationTo for offsets over a wide range of angles """ for fromPolarAng in (-87.1, -25.5, 0.43, 36.7, 87.0): for fromEquatAng in (0, 41.0): # should not matter fromCoord = Coord(fromEquatAng, fromPolarAng) for fromOrient in (-89.9, -45.0, 0.01, 12.5, 89.0, 90.0): for dist in (0.0001, 0.01, 0.13, 5.73): sideA = 90.0 - fromPolarAng angB = 90.0 - fromOrient sideC = dist unknownAng, angA, sideB, angC = angSideAng(sideA, angB, sideC) self.assertFalse(unknownAng) predEquatAng = fromEquatAng + angC predPolarAng = 90 - sideB predAng = angA - 90 toCoord, toOrient = fromCoord.offset(fromOrient, dist) atPole, toEquatAng, toPolarAng = toCoord.getSphPos() places = 7 self.assertAlmostEqual(toEquatAng, predEquatAng, places=places) self.assertAlmostEqual(toPolarAng, predPolarAng, places=places) self.assertAlmostEqual(toOrient, predAng, places=places) fromCoord = Coord(fromEquatAng, fromPolarAng) toCoord = Coord(toEquatAng, toPolarAng) self.assertAlmostEqual(dist, fromCoord.angularSeparation(toCoord)) self.assertAlmostEqual(fromOrient, fromCoord.orientationTo(toCoord)) self.assertAlmostEqual(toOrient, wrapNear(180 + toCoord.orientationTo(fromCoord), toOrient))
def checkOne(self, testInput, expectedOutput): """Check one case Inputs: - testInput: a vector of inputs (ang, side, ang) - expectedOutput: a vector of outputs; if length(3) then (side, ang, side) and unknownAng assumed False if length(r) then (unknownAng, side, ang, side) """ if len(expectedOutput) == 3: expectedOutput = (False, ) + tuple(expectedOutput) elif len(expectedOutput) != 4: raise RuntimeError("len(expectedOutput) = %d; must be 3 or 4" % (len(expectedOutput), )) actualOutput = angSideAng(*testInput) # to handle angles comparing things like 359.999... to 0, compare sin and cos of ang_A and ang_C: procExpected = processOutput(expectedOutput) procActual = processOutput(actualOutput) if not numpy.allclose( procExpected, procActual, rtol=1.0e-10, atol=1.0e-10): self.fail("failed on input: %s; expected output = %s; actual output = %s" % \ (testInput, expectedOutput, actualOutput)) if actualOutput[1] < 0.0 or actualOutput[1] >= 360.0 \ or actualOutput[2] < 0.0 or actualOutput[2] >= 360.0 \ or actualOutput[3] < 0.0 or actualOutput[3] >= 360.0: self.fail("failed on input %s; one or more output angles out of range: %s" % \ (testInput, actualOutput))
def testOffset(self): """Test offset, angularSeparation and orientationTo for offsets over a wide range of angles """ for fromPolarAng in (-87.1, -25.5, 0.43, 36.7, 87.0): for fromEquatAng in (0, 41.0): # should not matter fromCoord = Coord(fromEquatAng, fromPolarAng) for fromOrient in (-89.9, -45.0, 0.01, 12.5, 89.0, 90.0): for dist in (0.0001, 0.01, 0.13, 5.73): sideA = 90.0 - fromPolarAng angB = 90.0 - fromOrient sideC = dist unknownAng, angA, sideB, angC = angSideAng( sideA, angB, sideC) self.assertFalse(unknownAng) predEquatAng = fromEquatAng + angC predPolarAng = 90 - sideB predAng = angA - 90 toCoord, toOrient = fromCoord.offset(fromOrient, dist) atPole, toEquatAng, toPolarAng = toCoord.getSphPos() places = 7 self.assertAlmostEqual(toEquatAng, predEquatAng, places=places) self.assertAlmostEqual(toPolarAng, predPolarAng, places=places) self.assertAlmostEqual(toOrient, predAng, places=places) fromCoord = Coord(fromEquatAng, fromPolarAng) toCoord = Coord(toEquatAng, toPolarAng) self.assertAlmostEqual( dist, fromCoord.angularSeparation(toCoord)) self.assertAlmostEqual( fromOrient, fromCoord.orientationTo(toCoord)) self.assertAlmostEqual( toOrient, wrapNear(180 + toCoord.orientationTo(fromCoord), toOrient))