s2js
    Preparing search index...

    Namespace chordangle

    ChordAngle represents the angle subtended by a chord (i.e., the straight line segment connecting two points on the sphere). Its representation makes it very efficient for computing and comparing distances, but unlike Angle it is only capable of representing angles between 0 and π radians. Generally, ChordAngle should only be used in loops where many angles need to be calculated and compared. Otherwise it is simpler to use Angle.

    ChordAngle loses some accuracy as the angle approaches π radians. There are several different ways to measure this error, including the representational error (i.e., how accurately ChordAngle can represent angles near π radians), the conversion error (i.e., how much precision is lost when an Angle is converted to an ChordAngle), and the measurement error (i.e., how accurate the ChordAngle(a, b) constructor is when the points A and B are separated by angles close to π radians). All of these errors differ by a small constant factor.

    For the measurement error (which is the largest of these errors and also the most important in practice), let the angle between A and B be (π - x) radians, i.e. A and B are within "x" radians of being antipodal. The corresponding chord length is:

    r = 2 * sin((π - x) / 2) = 2 * cos(x / 2)
    

    For values of x not close to π the relative error in the squared chord length is at most 4.5 * dblEpsilon (see MaxPointError below). The relative error in "r" is thus at most 2.25 * dblEpsilon ~= 5e-16. To convert this error into an equivalent angle, we have:

    |dr / dx| = sin(x / 2)
    

    and therefore:

    |dx| = dr / sin(x / 2)
         = 5e-16 * (2 * cos(x / 2)) / sin(x / 2)
         = 1e-15 / tan(x / 2)
    

    The maximum error is attained when:

    x  = |dx|
       = 1e-15 / tan(x / 2)
      ~= 1e-15 / (x / 2)
      ~= sqrt(2e-15)
    

    In summary, the measurement error for an angle (π - x) is at most:

    dx  = min(1e-15 / tan(x / 2), sqrt(2e-15))
      (~= min(2e-15 / x, sqrt(2e-15)) when x is small)
    

    On the Earth's surface (assuming a radius of 6371km), this corresponds to the following worst-case measurement errors:

    Accuracy:             Unless antipodal to within:
    ---------             ---------------------------
    6.4 nanometers        10,000 km (90 degrees)
    1 micrometer          81.2 kilometers
    1 millimeter          81.2 meters
    1 centimeter          8.12 meters
    28.5 centimeters      28.5 centimeters
    

    The representational and conversion errors referred to earlier are somewhat smaller than this. For example, maximum distance between adjacent representable ChordAngle values is only 13.5 cm rather than 28.5 cm. To see this, observe that the closest representable value to r^2 = 4 is r^2 = 4 * (1 - dblEpsilon / 2). Thus r = 2 * (1 - dblEpsilon / 4) and the angle between these two representable values is:

    x  = 2 * acos(r / 2)
       = 2 * acos(1 - dblEpsilon / 4)
      ~= 2 * asin(sqrt(dblEpsilon / 2)
      ~= sqrt(2 * dblEpsilon)
      ~= 2.1e-8
    

    which is 13.5 cm on the Earth's surface.

    The worst case rounding error occurs when the value halfway between these two representable values is rounded up to 4. This halfway value is r^2 = (4 * (1 - dblEpsilon / 4)), thus r = 2 * (1 - dblEpsilon / 8) and the worst case rounding error is:

    x  = 2 * acos(r / 2)
       = 2 * acos(1 - dblEpsilon / 8)
      ~= 2 * asin(sqrt(dblEpsilon / 4)
      ~= sqrt(dblEpsilon)
      ~= 1.5e-8
    

    which is 9.5 cm on the Earth's surface.

    Constructors

    fromAngle
    fromSquaredLength

    Other

    ChordAngle
    add
    angle
    cos
    expanded
    infChordAngle
    isInfinity
    isSpecial
    isValid
    maxAngleError
    maxPointError
    predecessor
    sin
    sin2
    sub
    successor
    tan