From 6fe084df3b089835a850578628b3f7128cc2b001 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 Jun 2010 16:27:35 +0000 Subject: [PATCH] Introduced the use of atan2 in place of asin/acos for reliability and simplicity --- src/osgSim/SphereSegment.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/osgSim/SphereSegment.cpp b/src/osgSim/SphereSegment.cpp index 77d4c4223..1ad5c2a57 100644 --- a/src/osgSim/SphereSegment.cpp +++ b/src/osgSim/SphereSegment.cpp @@ -289,16 +289,15 @@ void SphereSegment::setArea(const osg::Vec3& v, float azRange, float elevRange) vec.normalize(); // Make sure we're unit length // Calculate the elevation range - float elev = asin(vec.z()); // Elevation angle + float xyLen = sqrtf(vec.x()*vec.x() + vec.y()*vec.y()); + float elev = atan2(vec.z(), xyLen); // Elevation angle + elevRange /= 2.0f; _elevMin = elev - elevRange; _elevMax = elev + elevRange; - // Calculate the azimuth range, cater for trig ambiguities - float xyLen = cos(elev); - float az; - if(vec.x() != 0.0f) az = asin(vec.x()/xyLen); - else az = acos(vec.y()/xyLen); + // Calculate the azimuth range, cater for trig ambiguities + float az = atan2(vec.x(), vec.y()); azRange /= 2.0f; _azMin = az - azRange;