You are here

function earth_asin_safe in Location 7.5

Same name and namespace in other branches
  1. 5.3 earth.inc \earth_asin_safe()
  2. 6.3 earth.inc \earth_asin_safe()
  3. 7.3 earth.inc \earth_asin_safe()
  4. 7.4 earth.inc \earth_asin_safe()

This is a helper function to avoid errors when using the asin() PHP function. asin is only real for values between -1 and 1. If a value outside that range is given it returns NAN (not a number), which we don't want to happen. So this just rounds values outside this range to -1 or 1 first.

This means that calculations done using this function with $x outside the range will not be accurate. The alternative though is getting NAN, which is an error and won't give accurate results anyway.

1 call to earth_asin_safe()
earth_longitude_range in ./earth.inc
@todo This function uses earth_asin_safe so is not accurate for all possible parameter combinations. This means this function doesn't work properly for high distance values. This function needs to be re-written to work properly for larger…

File

./earth.inc, line 182
Trigonometry for calculating geographical distances. All function arguments and return values measure distances in metres and angles in degrees. The ellipsoid model is from the WGS-84 datum. Ka-Ping Yee, 2003-08-11

Code

function earth_asin_safe($x) {
  return asin(max(-1, min($x, 1)));
}