<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc strict="yes" ?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>

<rfc category="std" ipr="trust200902" updates="3693,4119,5491"
     docName="draft-ietf-geopriv-uncertainty-04">
  <front>
    <title abbrev="Uncertainty &amp; Confidence">
      Representation of Uncertainty and Confidence in PIDF-LO
    </title>

    <author initials="M." surname="Thomson" fullname="Martin Thomson">
      <organization>Mozilla</organization>
      <address>
        <postal>
          <street>331 E Evelyn Street</street>
          <city>Mountain View</city>
          <region>CA</region>
          <code>94041</code>
          <country>US</country>
        </postal>
        <email>martin.thomson@gmail.com</email>
      </address>
    </author>

    <author initials="J." surname="Winterbottom" fullname="James Winterbottom">
      <organization>Unaffiliated</organization>
      <address>
        <postal>
          <street></street>
          <country>AU</country>
        </postal>
        <email>a.james.winterbottom@gmail.com</email>
      </address>
    </author>

    <date year="2014"/>
    <area>RAI</area>
    <workgroup>GEOPRIV</workgroup>
    <keyword>Internet-Draft</keyword>
    <keyword>Uncertainty</keyword>
    <keyword>Confidence</keyword>
    <keyword>Location</keyword>
    <keyword>PIDF-LO</keyword>
    <keyword>Accuracy</keyword>
    <keyword>Precision</keyword>
    <keyword>GML</keyword>
    <keyword>Geodetic</keyword>
    <keyword>Centroid</keyword>

    <abstract>
      <t>
        This document defines key concepts of uncertainty and confidence as they pertain to location
        information.  Methods for the manipulation of location estimates that include uncertainty
        information are outlined.
      </t>
      <t>
        This document normatively updates the definition of location information representations
        defined in RFC 4119 and RFC 5491.  It also deprecates related terminology defined in RFC
        3693.
      </t>
    </abstract>
  </front>

  <middle>

    <section anchor="intro" title="Introduction">
      <t>
        Location information represents an estimation of the position of a <xref
        target="RFC6280">Target</xref>.  Under ideal circumstances, a location estimate precisely
        reflects the actual location of the Target.  For automated systems that determine location,
        there are many factors that introduce errors into the measurements that are used to
        determine location estimates.
      </t>

      <t>
        The process by which measurements are combined to generate a location estimate is outside of
        the scope of work within the IETF.  However, the results of such a process are carried in
        IETF data formats and protocols.  This document outlines how uncertainty, and its associated
        datum, confidence, are expressed and interpreted.
      </t>

      <t>
        This document provides a common nomenclature for discussing uncertainty and confidence as
        they relate to location information.
      </t>

      <t>
        This document also provides guidance on how to manage location information that includes
        uncertainty.  Methods for expanding or reducing uncertainty to obtain a required level of
        confidence are described.  Methods for determining the probability that a Target is within a
        specified region based on its location estimate are described.  These methods are simplified
        by making certain assumptions about the location estimate and are designed to be applicable
        to location estimates in a relatively small geographic area.
      </t>

      <t>
        A confidence extension for the <xref target="RFC4119">Presence Information Data Format -
        Location Object (PIDF-LO)</xref> is described.
      </t>

      <t>
        This document describes methods that can be used in combination with automatically
        determined location information.  These are statistically-based methods.
      </t>

      <section anchor="terminology" title="Conventions and Terminology">
        <t>
          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD
          NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as
          described in <xref target="RFC2119"/>.
        </t>
        <t>
          This document assumes a basic understanding of the principles of mathematics, particularly
          statistics and geometry.
        </t>
        <t>
          Some terminology is borrowed from <xref target="RFC3693"/> and <xref target="RFC6280"/>,
          in particular Target.
        </t>

        <t>
          Mathematical formulae are presented using the following notation: add <spanx
          style="verb">+</spanx>, subtract <spanx style="verb">-</spanx>, multiply <spanx
          style="verb">*</spanx>, divide <spanx style="verb">/</spanx>, power <spanx
          style="verb">^</spanx> and absolute value <spanx style="verb">|x|</spanx>.  Precedence
          follows established conventions: power operations precede multiply and divide, multiply
          and divide precede add and subtract, and parentheses are used to indicate operations that
          are applied together.  Mathematical functions are represented by common abbreviations:
          square root <spanx style="verb">sqrt(x)</spanx>, sine <spanx style="verb">sin(x)</spanx>,
          cosine <spanx style="verb">cos(x)</spanx>, inverse cosine <spanx
          style="verb">acos(x)</spanx>, tangent <spanx style="verb">tan(x)</spanx>, inverse tangent
          <spanx style="verb">atan(x)</spanx>, two-argument inverse tangent <spanx
          style="verb">atan2(y,x)</spanx>, error function <spanx style="verb">erf(x)</spanx>, and
          inverse error function <spanx style="verb">erfinv(x)</spanx>.
        </t>
      </section>

    </section>

    <section anchor="general" title="A General Definition of Uncertainty">
      <t>
        Uncertainty results from the limitations of measurement.  In measuring any observable
        quantity, errors from a range of sources affect the result.  Uncertainty is a quantification
        of what is known about the observed quantity, either through the limitations of measurement
        or through inherent variability of the quantity.
      </t>

      <t>
        Uncertainty is most completely described by a probability distribution.  A probability
        distribution assigns a probability to possible values for the quantity.
      </t>

      <t>
        A probability distribution describing a measured quantity can be arbitrarily complex and so
        it is desirable to find a simplified model.  One approach commonly taken is to reduce the
        probability distribution to a confidence interval.  Many alternative models are used in
        other areas, but study of those is not the focus of this document.
      </t>

      <t>
        In addition to the central estimate of the observed quantity, a confidence interval is
        succinctly described by two values: an error range and a confidence.  The error range
        describes an interval and the confidence describes an estimated upper bound on the
        probability that a "true" value is found within the extents defined by the error.
      </t>

      <t>
        In the following example, a measurement result for a length is shown as a nominal value with
        additional information on error range (0.0043 meters) and confidence (95%).
        <list style="empty">
          <t>
            e.g.  x = 1.00742 +/- 0.0043 meters at 95% confidence
          </t>
        </list>
        This result indicates that the measurement indicates that the value of <spanx
        style="verb">x</spanx> between 1.00312 and 1.01172 meters with 95% probability.  No other
        assertion is made: in particular, this does not assert that x is 1.00742.
      </t>

      <t>
        Uncertainty and confidence for location estimates can be derived in a number of ways.  This
        document does not attempt to enumerate the many methods for determining uncertainty.  <xref
        target="ISO.GUM"/> and <xref target="NIST.TN1297"/> provide a set of general guidelines for
        determining and manipulating measurement uncertainty.  This document applies that general
        guidance for consumers of location information.
      </t>

      <t>
        As a statistical measure, values determined for uncertainty are determined based on
        information in the aggregate, across numerous individual estimates.  An individual estimate
        might be determined to be "correct" - by using a survey to validate the result, for example
        - without invalidating the statistical assertion.
      </t>
      <t>
        This understanding of estimates in the statistical sense explains why asserting a confidence
        of 100%, which might seem intuitively correct, is rarely advisable.
      </t>

      <section title="Uncertainty as a Probability Distribution">
        <t>
          The Probability Density Function (PDF) that is described by uncertainty indicates the
          probability that the "true" value lies at any one point.  The shape of the probability
          distribution can vary depending on the method that is used to determine the result.  The
          two probability density functions most generally applicable to location information are
          considered in this document:
          <list style="symbols">
            <t>
              The normal PDF (also referred to as a Gaussian PDF) is used where a large number of
              small random factors contribute to errors.  The value used for the error range in a
              normal PDF is related to the standard deviation of the distribution.
            </t>

            <t>
              A rectangular PDF is used where the errors are known to be consistent across a limited
              range.  A rectangular PDF can occur where a single error source, such as a rounding
              error, is significantly larger than other errors.  A rectangular PDF is often
              described by the half-width of the distribution; that is, half the width of the
              distribution.
            </t>
          </list>
        </t>

        <t>
          Each of these probability density functions can be characterized by its center point, or
          mean, and its width.  For a normal distribution, uncertainty and confidence together are
          related to the standard deviation of the function (see <xref target="scaling"/>).  For a
          rectangular distribution, the half-width of the distribution is used.
        </t>

        <t>
          <xref target="pdf"/> shows a normal and rectangular probability density function with the
          mean (m) and standard deviation (s) labelled.  The half-width (h) of the rectangular
          distribution is also indicated.
        </t>

        <figure anchor="pdf" title="Normal and Rectangular Probability Density Functions">
          <!-- gnuplot instructions:
               set terminal dumb 70 20
               set output "normal.txt"
               set tics out
               # normal PDF with stddev = 1
               f(x) = exp(x**2/-2)/sqrt(2*pi)
               # rectangular PDF with stddev = 1 (i.e. sqrt(3) half-width)
               g(x) = (abs(x) < sqrt(3)) ? 1 / sqrt(3) / 2 : 0
               plot [-3:3] f(x), g(x)
          -->
          <artwork><![CDATA[
                             *****             *** Normal PDF
                           **  :  **           --- Rectangular PDF
                         **    :    **
                        **     :     **
             .---------*---------------*---------.
             |        **       :       **        |
             |       **        :        **       |
             |      * <-- s -->:          *      |
             |     * :         :         : *     |
             |    **           :           **    |
             |   *   :         :         :   *   |
             |  *              :              *  |
             |**     :         :         :     **|
            **                 :                 **
         *** |       :         :         :       | ***
     *****   |                 :<------ h ------>|   *****
 .****-------+.......:.........:.........:.......+-------*****.
                               m
                               ]]></artwork>
        </figure>

        <t>
          For a given PDF, the value of the PDF describes the probability that the "true" value is
          found at that point.  Confidence for any given interval is the total probability of the
          "true" value being in that range, defined as the integral of the PDF over the interval.

          <list style="empty">
            <t>
              The probability of the "true" value falling between two points is found by finding the
              area under the curve between the points (that is, the integral of the curve between
              the points).  For any given PDF, the area under the curve for the entire range from
              negative infinity to positive infinity is 1 or (100%).  Therefore, the confidence over
              any interval of uncertainty is always less than 100%.
            </t>
          </list>

          <xref target="pdfintegral"/> shows how confidence is determined for a normal distribution.
          The area of the shaded region gives the confidence (c) for the interval between <spanx
          style="verb">m-u</spanx> and <spanx style="verb">m+u</spanx>.
        </t>

        <figure anchor="pdfintegral" title="Confidence as the Integral of a PDF">
          <artwork><![CDATA[
                             *****
                           **:::::**
                         **:::::::::**
                        **:::::::::::**
                       *:::::::::::::::*
                      **:::::::::::::::**
                     **:::::::::::::::::**
                    *:::::::::::::::::::::*
                   *:::::::::::::::::::::::*
                  **:::::::::::::::::::::::**
                 *:::::::::::: c ::::::::::::*
                *:::::::::::::::::::::::::::::*
              **|:::::::::::::::::::::::::::::|**
            **  |:::::::::::::::::::::::::::::|  **
         ***    |:::::::::::::::::::::::::::::|    ***
     *****      |:::::::::::::::::::::::::::::|      *****
 .****..........!:::::::::::::::::::::::::::::!..........*****.
                |              |              |
              (m-u)            m            (m+u)
]]></artwork>
        </figure>

<!--
        <t> This area can be found using the expression (where s is the standard deviation): <list
        style="empty"> <t> c = erf(u / s / sqrt(2)) </t> </list> Therefore, a confidence of 95%
        corresponds to an uncertainty of 1.96 standard deviations.  </t>
-->

        <t>
          In <xref target="scaling"/>, methods are described for manipulating uncertainty if the
          shape of the PDF is known.
        </t>
      </section>

      <section title="Deprecation of the Terms Precision and Resolution">
        <t>
          The terms <spanx style="emph">Precision</spanx> and <spanx style="emph">Resolution</spanx>
          are defined in <xref target="RFC3693">RFC 3693</xref>.  These definitions were intended to
          provide a common nomenclature for discussing uncertainty; however, these particular terms
          have many different uses in other fields and their definitions are not sufficient to avoid
          confusion about their meaning.  These terms are unsuitable for use in relation to
          quantitative concepts when discussing uncertainty and confidence in relation to location
          information.
        </t>
      </section>

      <section title="Accuracy as a Qualitative Concept">
        <t>
          Uncertainty is a quantitative concept.  The term <spanx style="emph">accuracy</spanx> is
          useful in describing, qualitatively, the general concepts of location information.
          Accuracy is generally useful when describing qualitative aspects of location estimates.
          Accuracy is not a suitable term for use in a quantitative context.
        </t>

        <t>
          For instance, it could be appropriate to say that a location estimate with uncertainty
          <spanx style="verb">X</spanx> is more accurate than a location estimate with uncertainty
          <spanx style="verb">2X</spanx> at the same confidence.  It is not appropriate to assign a
          number to "accuracy", nor is it appropriate to refer to any component of uncertainty or
          confidence as "accuracy".  That is, to say that the "accuracy" for the first location
          estimate is <spanx style="verb">X</spanx> would be an erroneous use of this term.
        </t>
      </section>
    </section>

    <section anchor="location" title="Uncertainty in Location">
      <t>
        A <spanx style="emph">location estimate</spanx> is the result of location determination.  A
        location estimate is subject to uncertainty like any other observation.  However, unlike a
        simple measure of a one dimensional property like length, a location estimate is specified
        in two or three dimensions.
      </t>

      <t>
        Uncertainty in two or three dimensional locations can be described using confidence
        intervals.  The confidence interval for a location estimate in two or three dimensional
        space is expressed as a subset of that space.  This document uses the term <spanx
        style="emph">region of uncertainty</spanx> to refer to the area or volume that describes the
        confidence interval.
      </t>

      <t>
        Areas or volumes that describe regions of uncertainty can be formed by the combination of
        two or three one-dimensional ranges, or more complex shapes could be described (for example,
        the shapes in <xref target="RFC5491"/>).
      </t>

      <section title="Targets as Points in Space">
        <t>
          This document makes a simplifying assumption that the Target of the PIDF-LO occupies just
          a single point in space.  While this is clearly false in virtually all scenarios with any
          practical application, it is often a reasonable simplifying assumption to make.
        </t>
        <t>
          To a large extent, whether this simplification is valid depends on the size of the target
          relative to the size of the uncertainty region.  When locating a personal device using
          contemporary location determination techniques, the space the device occupies relative to
          the uncertainty is proportionally quite small.  Even where that device is used as a proxy
          for a person, the proportions change little.
        </t>
        <t>
          This assumption is less useful as uncertainty becomes small relative to the size of the
          Target of the PIDF-LO (or conversely, as uncertainty becomes small relative to the
          Target).  For instance, describing the location of a football stadium or small country
          would include a region of uncertainty that is only slightly larger than the Target itself.
          In these cases, much of the guidance in this document is not applicable.  Indeed, as the
          accuracy of location determination technology improves, it could be that the advice this
          document contains becomes less relevant by the same measure.
        </t>
      </section>

      <section title="Representation of Uncertainty and Confidence in PIDF-LO">
        <t>
          A set of shapes suitable for the expression of uncertainty in location estimates in the
          Presence Information Data Format - Location Object (PIDF-LO) are described in <xref
          target="GeoShape"/>.  These shapes are the recommended form for the representation of
          uncertainty in <xref target="RFC4119">PIDF-LO</xref> documents.
        </t>

        <t>
          The PIDF-LO can contain uncertainty, but does not include an indication of confidence.
          <xref target="RFC5491"/> defines a fixed value of 95%.  Similarly, the PIDF-LO format does
          not provide an indication of the shape of the PDF.  <xref target="confidence"/> defines
          elements to convey this information in PIDF-LO.
        </t>

        <t>
          Absence of uncertainty information in a PIDF-LO document does not indicate that there is
          no uncertainty in the location estimate.  Uncertainty might not have been calculated for
          the estimate, or it may be withheld for privacy purposes.
        </t>

        <t>
          If the Point shape is used, confidence and uncertainty are unknown; a receiver can either
          assume a confidence of 0% or infinite uncertainty.  The same principle applies on the
          altitude axis for two-dimension shapes like the Circle.
        </t>
      </section>

      <section title="Uncertainty and Confidence for Civic Addresses">
        <t>
          Automatically determined <xref target="RFC5139">civic addresses</xref> inherently include
          uncertainty, based on the area of the most precise element that is specified.  In this
          case, uncertainty is effectively described by the presence or absence of elements.  To the
          recipient of location information, elements that are not present are uncertain.
        </t>

        <t>
          To apply the concept of uncertainty to civic addresses, it is helpful to unify the
          conceptual models of civic address with geodetic location information.  This is
          particularly useful when considering civic addresses that are determined using reverse
          geocoding (that is, the process of translating geodetic information into civic addresses).
        </t>

        <t>
          In the unified view, a civic address defines a series of (sometimes non-orthogonal)
          spatial partitions.  The first is the implicit partition that identifies the surface of
          the earth and the space near the surface.  The second is the country.  Each label that is
          included in a civic address provides information about a different set of spatial
          partitions.  Some partitions require slight adjustments from a standard interpretation:
          for instance, a road includes all properties that adjoin the street.  Each label might
          need to be interpreted with other values to provide context.
        </t>

        <t>
          As a value at each level is interpreted, one or more spatial partitions at that level are
          selected, and all other partitions of that type are excluded.  For non-orthogonal
          partitions, only the portion of the partition that fits within the existing space is
          selected.  This is what distinguishes King Street in Sydney from King Street in Melbourne.
          Each defined element selects a partition of space.  The resulting location is the
          intersection of all selected spaces.
        </t>

        <t>
          The resulting spatial partition can be considered as a region of uncertainty.
          <list style="hanging">
            <t hangText="Note:">
              This view is a potential perspective on the process of geo-coding - the translation of
              a civic address to a geodetic location.
            </t>
          </list>
        </t>

        <t>
          Uncertainty in civic addresses can be increased by removing elements.  This does not
          increase confidence unless additional information is used.  Similarly, arbitrarily
          increasing uncertainty in a geodetic location does not increase confidence.
        </t>
      </section>

      <section title="DHCP Location Configuration Information and Uncertainty">
        <t>
          Location information is often measured in two or three dimensions; expressions of
          uncertainty in one dimension only are rare.  The "resolution" parameters in <xref
          target="RFC6225"/> provide an indication of how many bits of a number are valid, which
          could be interpreted as an expression of uncertainty in one dimension.
        </t>

        <t>
          <xref target="RFC6225"/> defines a means for representing uncertainty, but a value for
          confidence is not specified.  A default value of 95% confidence should be assumed for the
          combination of the uncertainty on each axis.  This is consistent with the transformation
          of those forms into the uncertainty representations from <xref target="RFC5491"/>.  That
          is, the confidence of the resultant rectangular polygon or prism is assumed to be 95%.
        </t>
      </section>

    </section>

    <section anchor="confidence" title="Representation of Confidence in PIDF-LO">
      <t>
        On the whole, a fixed definition for confidence is preferable, primarily because it ensures
        consistency between implementations.  Location generators that are aware of this constraint
        can generate location information at the required confidence.  Location recipients are able
        to make sensible assumptions about the quality of the information that they receive.
      </t>

      <t>
        In some circumstances - particularly with pre-existing systems - location generators might
        be unable to provide location information with consistent confidence.  Existing systems
        sometimes specify confidence at 38%, 67% or 90%.  Existing forms of expressing location
        information, such as that defined in <xref target="TS-3GPP-23_032"/>, contain elements that
        express the confidence in the result.
      </t>

      <t>
        The addition of a confidence element provides information that was previously unavailable to
        recipients of location information.  Without this information, a location server or
        generator that has access to location information with a confidence lower than 95% has two
        options:

        <list style="symbols">
          <t>
            The location server can scale regions of uncertainty in an attempt to acheive 95%
            confidence.  This scaling process significantly degrades the quality of the information,
            because the location server might not have the necessary information to scale
            appropriately; the location server is forced to make assumptions that are likely to
            result in either an overly conservative estimate with high uncertainty or a overestimate
            of confidence.
          </t>

          <t>
            The location server can ignore the confidence entirely, which results in giving the
            recipient a false impression of its quality.
          </t>
        </list>
        Both of these choices degrade the quality of the information provided.
      </t>

      <t>
        The addition of a confidence element avoids this problem entirely if a location recipient
        supports and understands the element.  A recipient that does not understand - and hence
        ignores - the confidence element is in no worse a position than if the location server
        ignored confidence.
      </t>

      <section anchor="conf" title="The &quot;confidence&quot; Element">
        <t>
          The confidence element MAY be added to the <spanx style="verb">location-info</spanx>
          element of the <xref target="RFC4119">Presence Information Data Format - Location Object
          (PIDF-LO)</xref> document.  This element expresses the confidence in the associated
          location information as a percentage.  A special <spanx style="verb">unknown</spanx> value
          is reserved to indicate that confidence is supported, but not known to the Location
          Generator.
        </t>

        <t>
          The confidence element optionally includes an attribute that indicates the shape of the
          probability density function (PDF) of the associated region of uncertainty.  Three values
          are possible: unknown, normal and rectangular.
        </t>

        <t>
          Indicating a particular PDF only indicates that the distribution approximately fits the
          given shape based on the methods used to generate the location information.  The PDF is
          normal if there are a large number of small, independent sources of error; rectangular if
          all points within the area have roughly equal probability of being the actual location of
          the Target; otherwise, the PDF MUST either be set to unknown or omitted.
        </t>

        <t>
          If a PIDF-LO does not include the confidence element, the confidence of the location
          estimate is 95%, as defined in <xref target="RFC5491"/>.
        </t>
        <t>
          A Point shape does not have uncertainty (or it has infinite uncertainty), so confidence is
          meaningless for a point; therefore, this element MUST be omitted if only a point is
          provided.
        </t>
      </section>

      <section title="Generating Locations with Confidence">
        <t>
          Location generators SHOULD attempt to ensure that confidence is equal in each dimension
          when generating location information.  This restriction, while not always practical,
          allows for more accurate scaling, if scaling is necessary.
        </t>
        <t>
          A confidence element MUST be included with all location information that includes
          uncertainty (that is, all forms other than a point).  A special <spanx
          style="verb">unknown</spanx> is used if confidence is not known.
        </t>
      </section>

      <section title="Consuming and Presenting Confidence">
        <t>

          The inclusion of confidence that is anything other than 95% presents a potentially
          difficult usability problem for applications that use location information.  Effectively
          communicating the probability that a location is incorrect to a user can be difficult.
        </t>
        <t>

          It is inadvisable to simply display locations of any confidence, or to display confidence
          in a separate or non-obvious fashion.  If locations with different confidence levels are
          displayed such that the distinction is subtle or easy to overlook - such as using fine
          graduations of color or transparency for graphical uncertainty regions, or displaying
          uncertainty graphically, but providing confidence as supplementary text - a user could
          fail to notice a difference in the quality of the location information that might be
          significant.
        </t>
        <t>

          Depending on the circumstances, different ways of handling confidence might be
          appropriate.  <xref target="manipulation"/> describes techniques that could be appropriate
          for consumers that use automated processing.
        </t>
        <t>

          Providing that the full implications of any choice for the application are understood,
          some amount of automated processing could be appropriate.  In a simple example,
          applications could choose to discard or suppress the display of location information if
          confidence does not meet a pre-determined threshold.
        </t>
        <t>

          In settings where there is an opportunity for user training, some of these problems might
          be mitigated by defining different operational procedures for handling location
          information at different confidence levels.
        </t>
      </section>
    </section>

    <section anchor="manipulation" title="Manipulation of Uncertainty">
      <t>
        This section deals with manipulation of location information that contains uncertainty.
      </t>

      <t>
        The following rules generally apply when manipulating location information:
        <list style="symbols">

          <t>
            Where calculations are performed on coordinate information, these should be performed in
            Cartesian space and the results converted back to latitude, longitude and altitude.  A
            method for converting to and from Cartesian coordinates is included in <xref
            target="ecef2geo"/>.
            <list style="empty">
              <t>
                While some approximation methods are useful in simplifying calculations, treating
                latitude and longitude as Cartesian axes is never advisable.  The two axes are not
                orthogonal.  Errors can arise from the curvature of the earth and from the
                convergence of longitude lines.
              </t>
            </list>
          </t>

          <t>
            Normal rounding rules do not apply when rounding uncertainty.  When rounding, the region
            of uncertainty always increases (that is, errors are rounded up) and confidence is
            always rounded down (see <xref target="NIST.TN1297"/>).  This means that any
            manipulation of uncertainty is a non-reversible operation; each manipulation can result
            in the loss of some information.
          </t>
        </list>
      </t>

      <section anchor="nominal" title="Reduction of a Location Estimate to a Point">
        <t>
          Manipulating location estimates that include uncertainty information requires additional
          complexity in systems.  In some cases, systems only operate on definitive values, that is,
          a single point.
        </t>

        <t>
          This section describes algorithms for reducing location estimates to a simple form without
          uncertainty information.  Having a consistent means for reducing location estimates allows
          for interaction between applications that are able to use uncertainty information and
          those that cannot.
        </t>

        <t>
          <list style="hanging">
            <t hangText="Note:">
              Reduction of a location estimate to a point constitutes a reduction in information.
              Removing uncertainty information can degrade results in some applications.  Also,
              there is a natural tendency to misinterpret a point location as representing a
              location without uncertainty.  This could lead to more serious errors.  Therefore,
              these algorithms should only be applied where necessary.
            </t>
          </list>
        </t>

        <t>
          Several different approaches can be taken when reducing a location estimate to a point.
          Different methods each make a set of assumptions about the properties of the PDF and the
          selected point; no one method is more "correct" than any other.  For any given region of
          uncertainty, selecting an arbitrary point within the area could be considered valid;
          however, given the aforementioned problems with point locations, a more rigorous approach
          is appropriate.
        </t>

        <t>
          Given a result with a known distribution, selecting the point within the area that has the
          highest probability is a more rigorous method.  Alternatively, a point could be selected
          that minimizes the overall error; that is, it minimizes the expected value of the
          difference between the selected point and the "true" value.
        </t>

        <t>
          If a rectangular distribution is assumed, the centroid of the area or volume minimizes the
          overall error.  Minimizing the error for a normal distribution is mathematically complex.
          Therefore, this document opts to select the centroid of the region of uncertainty when
          selecting a point.
        </t>

        <section anchor="centroid" title="Centroid Calculation">
          <t>
            For regular shapes, such as Circle, Sphere, Ellipse and Ellipsoid, this approach equates
            to the center point of the region.  For regions of uncertainty that are expressed as
            regular Polygons and Prisms the center point is also the most appropriate selection.
          </t>

          <t>
            For the Arc-Band shape and non-regular Polygons and Prisms, selecting the centroid of
            the area or volume minimizes the overall error.  This assumes that the PDF is
            rectangular.
            <list style="hanging">
              <t hangText="Note:">
                The centroid of a concave Polygon or Arc-Band shape is not necessarily within the
                region of uncertainty.
              </t>
            </list>
          </t>

          <section title="Arc-Band Centroid">
            <t>
              The centroid of the Arc-Band shape is found along a line that bisects the arc.  The
              centroid can be found at the following distance from the starting point of the
              arc-band (assuming an arc-band with an inner radius of <spanx style="verb">r</spanx>,
              outer radius <spanx style="verb">R</spanx>, start angle <spanx style="verb">a</spanx>,
              and opening angle <spanx style="verb">o</spanx>):
              <list style="empty">
                <t>
                  d = 4 * sin(o/2) * (R*R + R*r + r*r) / (3*o*(R + r))
                </t>
              </list>
              This point can be found along the line that bisects the arc; that is, the line at an
              angle of <spanx style="verb">a&nbsp;+&nbsp;(o/2)</spanx>.
            </t>

          </section>

          <section anchor="centroid-polygon" title="Polygon Centroid">
            <!-- 2d: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ -->

            <!-- three is too many dimensions for the standard equations.  Need to find upward normal and convert x, y, z into an x and y on a plane perpindicular to the normal. then convert back -->


            <t>
              Calculating a centroid for the Polygon and Prism shapes is more complex.  Polygons
              that are specified using geodetic coordinates are not necessarily coplanar.  For
              Polygons that are specified without an altitude, choose a value for altitude before
              attempting this process; an altitude of 0 is acceptable.
              <list style="empty">
                <t>
                  The method described in this section is simplified by assuming that the surface of
                  the earth is locally flat.  This method degrades as polygons become larger; see
                  <xref target="GeoShape"/> for recommendations on polygon size.
                </t>
              </list>
            </t>

            <t>
              The polygon is translated to a new coordinate system that has an x-y plane roughly
              parallel to the polygon.  This enables the elimination of z-axis values and
              calculating a centroid can be done using only x and y coordinates.  This requires that
              the upward normal for the polygon is known.
            </t>

            <t>
              To translate the polygon coordinates, apply the process described in <xref
              target="polygonupnormal"/> to find the normal vector <spanx
              style="verb">N&nbsp;=&nbsp;[Nx,Ny,Nz]</spanx>.  This value should be made a unit
              vector to ensure that the transformation matrix is a special orthogonal matrix.  From
              this vector, select two vectors that are perpendicular to this vector and combine
              these into a transformation matrix.
            </t>

            <t>
              If <spanx style="verb">Nx</spanx> and <spanx style="verb">Ny</spanx> are non-zero, the
              matrices in <xref target="transformmatrices"/> can be used, given <spanx
              style="verb">p&nbsp;=&nbsp;sqrt(Nx^2&nbsp;+&nbsp;Ny^2)</spanx>.  More transformations
              are provided later in this section for cases where <spanx style="verb">Nx</spanx> or
              <spanx style="verb">Ny</spanx> are zero.
            </t>

            <figure anchor="transformmatrices" title="Recommended Transformation Matrices">
            <artwork><![CDATA[
       [   -Ny/p     Nx/p     0  ]         [ -Ny/p  -Nx*Nz/p  Nx ]
   T = [ -Nx*Nz/p  -Ny*Nz/p   p  ]    T' = [  Nx/p  -Ny*Nz/p  Ny ]
       [    Nx        Ny      Nz ]         [   0      p       Nz ]
              (Transform)                    (Reverse Transform)
]]></artwork>
            </figure>

            <t>
              To apply a transform to each point in the polygon, form a matrix from the Cartesian
              Earth-Centered, Earth-Fixed (ECEF) coordinates and use matrix multiplication to
              determine the translated coordinates.
            </t>

            <figure anchor="transform" title="Transformation">
              <artwork><![CDATA[
   [   -Ny/p     Nx/p     0  ]   [ x[1]  x[2]  x[3]  ...  x[n] ]
   [ -Nx*Nz/p  -Ny*Nz/p   p  ] * [ y[1]  y[2]  y[3]  ...  y[n] ]
   [    Nx        Ny      Nz ]   [ z[1]  z[2]  z[3]  ...  z[n] ]

       [ x'[1]  x'[2]  x'[3]  ... x'[n] ]
     = [ y'[1]  y'[2]  y'[3]  ... y'[n] ]
       [ z'[1]  z'[2]  z'[3]  ... z'[n] ]
]]></artwork>
            </figure>

            <t>
              Alternatively, direct multiplication can be used to achieve the same result:
              <list style="empty">
                <t>
                  x'[i] = -Ny * x[i] / p + Nx * y[i] / p
                </t>
                <t>
                  y'[i] = -Nx * Nz * x[i] / p - Ny * Nz * y[i] / p + p * z[i]
                </t>
                <t>
                  z'[i] = Nx * x[i] + Ny * y[i] + Nz * z[i]
                </t>
              </list>
            </t>

            <t>
              The first and second rows of this matrix (<spanx style="verb">x'</spanx> and <spanx
              style="verb">y'</spanx>) contain the values that are used to calculate the centroid of
              the polygon.  To find the centroid of this polygon, first find the area using:
              <list style="empty">
                <t>
                  A = sum from i=1..n of (x'[i]*y'[i+1]-x'[i+1]*y'[i]) / 2
                </t>
              </list>
              For these formulae, treat each set of coordinates as circular, that is <spanx
              style="verb">x'[0]&nbsp;==&nbsp;x'[n]</spanx> and <spanx
              style="verb">x'[n+1]&nbsp;==&nbsp;x'[1]</spanx>.  Based on the area, the centroid
              along each axis can be determined by:
              <list style="empty">
                <t>
                  Cx' = sum (x'[i]+x'[i+1]) * (x'[i]*y'[i+1]-x'[i+1]*y'[i]) / (6*A)
                </t>
                <t>
                  Cy' = sum (y'[i]+y'[i+1]) * (x'[i]*y'[i+1]-x'[i+1]*y'[i]) / (6*A)
                </t>
              </list>
              <list style="hanging">
                <t hangText="Note:">
                  The formula for the area of a polygon will return a negative value if the polygon
                  is specified in clockwise direction.  This can be used to determine the
                  orientation of the polygon.
                </t>
              </list>
            </t>

            <t>
              The third row contains a distance from a plane parallel to the polygon.  If the
              polygon is coplanar, then the values for <spanx style="verb">z'</spanx> are identical;
              however, the constraints recommended in <xref target="RFC5491"/> mean that this is
              rarely the case.  To determine <spanx style="verb">Cz'</spanx>, average these values:
              <list style="empty">
                <t>
                  Cz' = sum z'[i] / n
                </t>
              </list>
            </t>

            <t>
              Once the centroid is known in the transformed coordinates, these can be transformed
              back to the original coordinate system.  The reverse transformation is shown in <xref
              target="reversetransform"/>.
            </t>

            <figure anchor="reversetransform" title="Reverse Transformation">
              <artwork><![CDATA[
   [ -Ny/p  -Nx*Nz/p  Nx ]     [       Cx'        ]   [ Cx ]
   [  Nx/p  -Ny*Nz/p  Ny ]  *  [       Cy'        ] = [ Cy ]
   [   0        p     Nz ]     [ sum of z'[i] / n ]   [ Cz ]
]]></artwork>
            </figure>

            <t>
              The reverse transformation can be applied directly as follows:
              <list style="empty">
                <t>
                Cx = -Ny * Cx' / p - Nx * Nz * Cy' / p + Nx * Cz'
                </t>
                <t>
                Cy = Nx * Cx' / p - Ny * Nz * Cy' / p + Ny * Cz'
                </t>
                <t>
                Cz = p * Cy' + Nz * Cz'
                </t>
              </list>
            </t>

            <t>
              The ECEF value <spanx style="verb">[Cx,Cy,Cz]</spanx> can then be converted back to
              geodetic coordinates.  Given a polygon that is defined with no altitude or equal
              altitudes for each point, the altitude of the result can either be ignored or reset
              after converting back to a geodetic value.
            </t>

            <t>
              The centroid of the Prism shape is found by finding the centroid of the base polygon
              and raising the point by half the height of the prism.  This can be added to altitude
              of the final result; alternatively, this can be added to <spanx
              style="verb">Cz'</spanx>, which ensures that negative height is correctly applied to
              polygons that are defined in a "clockwise" direction.
            </t>

            <t>
              The recommended transforms only apply if <spanx style="verb">Nx</spanx> and <spanx
              style="verb">Ny</spanx> are non-zero.  If the normal vector is <spanx
              style="verb">[0,0,1]</spanx> (that is, along the z-axis), then no transform is
              necessary.  Similarly, if the normal vector is <spanx style="verb">[0,1,0]</spanx> or
              <spanx style="verb">[1,0,0]</spanx>, avoid the transformation and use the x and z
              coordinates or y and z coordinates (respectively) in the centroid calculation phase.
              If either <spanx style="verb">Nx</spanx> or <spanx style="verb">Ny</spanx> are zero,
              the alternative transform matrices in <xref target="alternativetransform"/> can be
              used.  The reverse transform is the transpose of this matrix.
            </t>

            <figure anchor="alternativetransform" title="Alternative Transformation Matrices">
              <artwork><![CDATA[
 if Nx == 0:                              | if Ny == 0:
     [ 0  -Nz  Ny ]       [  0   1  0  ]  |            [ -Nz  0  Nx ]
 T = [ 1   0   0  ]  T' = [ -Nz  0  Ny ]  |   T = T' = [  0   1  0  ]
     [ 0   Ny  Nz ]       [  Ny  0  Nz ]  |            [  Nx  0  Nz ]
]]></artwork>
            </figure>

          </section>
        </section>
      </section>

      <section anchor="circle" title="Conversion to Circle or Sphere">
        <t>
          The Circle or Sphere are simple shapes that suit a range of applications.  A circle or
          sphere contains fewer units of data to manipulate, which simplifies operations on location
          estimates.
        </t>

        <t>
          The simplest method for converting a location estimate to a Circle or Sphere shape is to
          determine the centroid and then find the longest distance to any point in the region of
          uncertainty to that point.  This distance can be determined based on the shape type:
          <list style="hanging">
            <t hangText="Circle/Sphere:">
              No conversion necessary.
            </t>
            <t hangText="Ellipse/Ellipsoid:">
              The greater of either semi-major axis or altitude uncertainty.
            </t>
            <t hangText="Polygon/Prism:">
              The distance to the furthest vertex of the polygon (for a Prism, it is only necessary
              to check points on the base).
            </t>
            <t hangText="Arc-Band:">
              The furthest length from the centroid to the points where the inner and outer arc end.
              This distance can be calculated by finding the larger of the two following formulae:
              <list style="empty">
                <!-- if R == r && t = o/2:
                     fun graph == sqrt((sin(t)./t - cos(t)).^2 + sin(t).^2) -->
                <t>
                  X = sqrt( d*d + R*R - 2*d*R*cos(o/2) )
                </t>
                <t>
                  x = sqrt( d*d + r*r - 2*d*r*cos(o/2) )
                </t>
              </list>
            </t>
          </list>
        </t>

        <t>
          Once the Circle or Sphere shape is found, the associated confidence can be increased if
          the result is known to follow a normal distribution.  However, this is a complicated
          process and provides limited benefit.  In many cases it also violates the constraint that
          confidence in each dimension be the same.  Confidence should be unchanged when performing
          this conversion.
        </t>

        <t>
          Two dimensional shapes are converted to a Circle; three dimensional shapes are converted
          to a Sphere.
        </t>

      </section>

      <section title="Three-Dimensional to Two-Dimensional Conversion">
        <t>
          A three-dimensional shape can be easily converted to a two-dimensional shape by removing
          the altitude component.  A sphere becomes a circle; a prism becomes a polygon; an
          ellipsoid becomes an ellipse.  Each conversion is simple, requiring only the removal of
          those elements relating to altitude.
        </t>

        <t>
          The altitude is unspecified for a two-dimensional shape and therefore has unlimited
          uncertainty along the vertical axis.  The confidence for the two-dimensional shape is thus
          higher than the three-dimensional shape.  Assuming equal confidence on each axis, the
          confidence of the circle can be increased using the following approximate formula:
          <list style="empty">
            <t>
              C[2d] &gt;= C[3d] ^ (2/3)
            </t>
          </list>
          <spanx style="verb">C[2d]</spanx> is the confidence of the two-dimensional shape and
          <spanx style="verb">C[3d]</spanx> is the confidence of the three-dimensional shape.  For
          example, a Sphere with a confidence of 95% can be simplified to a Circle of equal radius
          with confidence of 96.6%.
        </t>
      </section>

      <section anchor="scaling" title="Increasing and Decreasing Uncertainty and Confidence">
        <t>
          The combination of uncertainty and confidence provide a great deal of information about
          the nature of the data that is being measured.  If uncertainty, confidence and PDF are
          known, certain information can be extrapolated.  In particular, the uncertainty can be
          scaled to meet a desired confidence or the confidence for a particular region of
          uncertainty can be found.
        </t>

        <t>
          In general, confidence decreases as the region of uncertainty decreases in size and
          confidence increases as the region of uncertainty increases in size.  However, this
          depends on the PDF; expanding the region of uncertainty for a rectangular distribution has
          no effect on confidence without additional information.  If the region of uncertainty is
          increased during the process of obfuscation (see <xref target="RFC6772"/>), then the
          confidence cannot be increased.
        </t>

        <t>
          A region of uncertainty that is reduced in size always has a lower confidence.
        </t>

        <t>
          A region of uncertainty that has an unknown PDF shape cannot be reduced in size reliably.
          The region of uncertainty can be expanded, but only if confidence is not increased.
        </t>

        <t>
          This section makes the simplifying assumption that location information is symmetrically
          and evenly distributed in each dimension.  This is not necessarily true in practice.  If
          better information is available, alternative methods might produce better results.
        </t>

        <section anchor="scale-rectangular" title="Rectangular Distributions">
          <t>
            Uncertainty that follows a rectangular distribution can only be decreased in size.
            Increasing uncertainty has no value, since it has no effect on confidence.  Since the
            PDF is constant over the region of uncertainty, the resulting confidence is determined
            by the following formula:
            <list style="empty">
              <t>
                Cr = Co * Ur / Uo
              </t>
            </list>
            Where <spanx style="verb">Uo</spanx> and <spanx style="verb">Ur</spanx> are the sizes of
            the original and reduced regions of uncertainty (either the area or the volume of the
            region); <spanx style="verb">Co</spanx> and <spanx style="verb">Cr</spanx> are the
            confidence values associated with each region.
          </t>

          <t>
            Information is lost by decreasing the region of uncertainty for a rectangular
            distribution.  Once reduced in size, the uncertainty region cannot subsequently be
            increased in size.
          </t>
        </section>

        <section anchor="scale-normal" title="Normal Distributions">
          <t>
            Uncertainty and confidence can be both increased and decreased for a normal
            distribution.  This calculation depends on the number of dimensions of the uncertainty
            region.
          </t>

          <t>
            For a normal distribution, uncertainty and confidence are related to the standard
            deviation of the function.  The following function defines the relationship between
            standard deviation, uncertainty, and confidence along a single axis:
            <list style="empty">
              <t>
                S[x] = U[x] / ( sqrt(2) * erfinv(C[x]) )
              </t>
            </list>
            Where <spanx style="verb">S[x]</spanx> is the standard deviation, <spanx
            style="verb">U[x]</spanx> is the uncertainty, and <spanx style="verb">C[x]</spanx> is
            the confidence along a single axis.  <spanx style="verb">erfinv</spanx> is the inverse
            error function.
          </t>

          <t>
            Scaling a normal distribution in two dimensions requires several assumptions.  Firstly,
            it is assumed that the distribution along each axis is independent.  Secondly, the
            confidence for each axis is assumed to be the same.  Therefore, the confidence along
            each axis can be assumed to be:
            <list style="empty">
              <t>
                C[x] = Co ^ (1/n)
              </t>
            </list>
            Where <spanx style="verb">C[x]</spanx> is the confidence along a single axis and <spanx
            style="verb">Co</spanx> is the overall confidence and <spanx style="verb">n</spanx> is
            the number of dimensions in the uncertainty.
          </t>

          <t>
            Therefore, to find the uncertainty for each axis at a desired confidence, <spanx
            style="verb">Cd</spanx>, apply the following formula:
            <list style="empty">
              <t>
                Ud[x] &lt;= U[x] * (erfinv(Cd ^ (1/n)) / erfinv(Co ^ (1/n)))
              </t>
            </list>
            For regular shapes, this formula can be applied as a scaling factor in each dimension to
            reach a required confidence.
          </t>
        </section>

      </section>

      <section anchor="inarea" title="Determining Whether a Location is Within a Given Region">
        <t>
          A number of applications require that a judgment be made about whether a Target is within
          a given region of interest.  Given a location estimate with uncertainty, this judgment can
          be difficult.  A location estimate represents a probability distribution, and the true
          location of the Target cannot be definitively known.  Therefore, the judgment relies on
          determining the probability that the Target is within the region.
        </t>

        <t>
          The probability that the Target is within a particular region is found by integrating the
          PDF over the region.  For a normal distribution, there are no analytical methods that can
          be used to determine the integral of the two or three dimensional PDF over an arbitrary
          region.  The complexity of numerical methods is also too great to be useful in many
          applications; for example, finding the integral of the PDF in two or three dimensions
          across the overlap between the uncertainty region and the target region.  If the PDF is
          unknown, no determination can be made without a simplifying assumption.
        </t>
        <t>

          When judging whether a location is within a given region, this document assumes that
          uncertainties are rectangular.  This introduces errors, but simplifies the calculations
          significantly.  Prior to applying this assumption, confidence should be scaled to 95%.
          <list style="hanging">
            <t hangText="Note:">
              The selection of confidence has a significant impact on the final result.  Only use a
              different confidence if an uncertainty value for 95% confidence cannot be found.
            </t>
          </list>
        </t>

        <t>
          Given the assumption of a rectangular distribution, the probability that a Target is found
          within a given region is found by first finding the area (or volume) of overlap between
          the uncertainty region and the region of interest.  This is multiplied by the confidence
          of the location estimate to determine the probability.  <xref target="overlap"/> shows an
          example of finding the area of overlap between the region of uncertainty and the region of
          interest.
        </t>

        <figure anchor="overlap" title="Area of Overlap Between Two Circular Regions">
          <artwork><![CDATA[
                 _.-""""-._
               .'          `.    _ Region of
              /              \  /  Uncertainty
           ..+-"""--..        |
        .-'  | :::::: `-.     |
      ,'     | :: Ao ::: `.   |
     /        \ :::::::::: \ /
    /          `._ :::::: _.X
   |              `-....-'   |
   |                         |
   |                         |
    \                       /
     `.                   .'  \_ Region of
       `._             _.'       Interest
          `--..___..--'
]]></artwork>
        </figure>

        <t>
          Once the area of overlap, <spanx style="verb">Ao</spanx>, is known, the probability that
          the Target is within the region of interest, <spanx style="verb">Pi</spanx>, is:
          <list style="empty">
            <t>
              Pi = Co * Ao / Au
            </t>
          </list>
          Given that the area of the region of uncertainty is <spanx style="verb">Au</spanx> and the
          confidence is <spanx style="verb">Co</spanx>.
        </t>

        <t>
          This probability is often input to a decision process that has a limited set of outcomes;
          therefore, a threshold value needs to be selected.  Depending on the application,
          different threshold probabilities might be selected.  A probability of 50% or greater is
          recommended before deciding that an uncertain value is within a given region.  If the
          decision process selects between two or more regions, as is required by <xref
          target="RFC5222"/>, then the region with the highest probability can be selected.
        </t>

        <section title="Determining the Area of Overlap for Two Circles">
          <t>
            Determining the area of overlap between two arbitrary shapes is a non-trivial process.
            Reducing areas to circles (see <xref target="circle"/>) enables the application of the
            following process.
          </t>

          <t>
            Given the radius of the first circle <spanx style="verb">r</spanx>, the radius of the
            second circle <spanx style="verb">R</spanx> and the distance between their center points
            <spanx style="verb">d</spanx>, the following set of formulas provide the area of overlap
            <spanx style="verb">Ao</spanx>.
            <list style="symbols">
              <t>
                If the circles don't overlap, that is <spanx
                style="verb">d&nbsp;&gt;=&nbsp;r+R</spanx>, <spanx style="verb">Ao</spanx> is zero.
              </t>
              <t>
                If one of the two circles is entirely within the other, that is <spanx
                style="verb">d&nbsp;&lt;=&nbsp;|r-R|</spanx>, the area of overlap is the area of the
                smaller circle.
              </t>
              <t>
                Otherwise, if the circles partially overlap, that is <spanx
                style="verb">d&nbsp;&lt;&nbsp;r+R</spanx> and <spanx
                style="verb">d&nbsp;&gt;&nbsp;|r-R|</spanx>, find <spanx style="verb">Ao</spanx>
                using:
                <list style="empty">
                  <t>
                    a = (r^2 - R^2 + d^2)/(2*d)
                  </t>
                  <t>
                    Ao = r^2*acos(a/r) + R^2*acos((d - a)/R) - d*sqrt(r^2 - a^2)
                  </t>
                </list>
              </t>
            </list>
            A value for <spanx style="verb">d</spanx> can be determined by converting the center
            points to Cartesian coordinates and calculating the distance between the two center
            points:
            <list style="empty">
              <t>
                d = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)
              </t>
            </list>
          </t>
        </section>

        <section title="Determining the Area of Overlap for Two Polygons">
          <t>
            A calculation of overlap based on polygons can give better results than the circle-based
            method.  However, efficient calculation of overlapping area is non-trivial.  Algorithms
            such as <xref target="Vatti92">Vatti's clipping algorithm</xref> can be used.
          </t>

          <t>
            For large polygonal areas, it might be that geodesic interpolation is used.  In these
            cases, altitude is also frequently omitted in describing the polygon.  For such shapes,
            a planar projection can still give a good approximation of the area of overlap if the
            larger area polygon is projected onto the local tangent plane of the smaller.  This is
            only possible if the only area of interest is that contained within the smaller polygon.
            Where the entire area of the larger polygon is of interest, geodesic interpolation is
            necessary.
          </t>
        </section>

      </section>

    </section>

    <section anchor="examples" title="Examples">
      <t>
        This section presents some examples of how to apply the methods described in <xref
        target="manipulation"/>.
      </t>

      <section title="Reduction to a Point or Circle">
        <t>
          Alice receives a location estimate from her LIS that contains an ellipsoidal region of
          uncertainty.  This information is provided at 19% confidence with a normal PDF.  A PIDF-LO
          extract for this information is shown in <xref target="ex-ellipse"/>.
        </t>

        <figure anchor="ex-ellipse">
          <artwork><![CDATA[
  <gp:geopriv>
    <gp:location-info>
      <gs:Ellipsoid srsName="urn:ogc:def:crs:EPSG::4979">
        <gml:pos>-34.407242 150.882518 34</gml:pos>
        <gs:semiMajorAxis uom="urn:ogc:def:uom:EPSG::9001">
          7.7156
        </gs:semiMajorAxis>
        <gs:semiMinorAxis uom="urn:ogc:def:uom:EPSG::9001">
          3.31
        </gs:semiMinorAxis>
        <gs:verticalAxis uom="urn:ogc:def:uom:EPSG::9001">
          28.7
        </gs:verticalAxis>
        <gs:orientation uom="urn:ogc:def:uom:EPSG::9102">
          43
        </gs:orientation>
      </gs:Ellipsoid>
      <con:confidence pdf="normal">95</con:confidence>
    </gp:location-info>
    <gp:usage-rules/>
  </gp:geopriv>
]]></artwork>
        </figure>

        <t>
          This information can be reduced to a point simply by extracting the center point, that is
          [-34.407242,&nbsp;150.882518,&nbsp;34].
        </t>

        <t>
          If some limited uncertainty were required, the estimate could be converted into a circle
          or sphere.  To convert to a sphere, the radius is the largest of the semi-major,
          semi-minor and vertical axes; in this case, 28.7 meters.
        </t>

        <t>
          However, if only a circle is required, the altitude can be dropped as can the altitude
          uncertainty (the vertical axis of the ellipsoid), resulting in a circle at
          [-34.407242,&nbsp;150.882518] of radius 7.7156 meters.
        </t>

        <t>
          Bob receives a location estimate with a Polygon shape (which roughly corresponds to the
          location of the Sydney Opera House).  This information is shown in <xref
          target="ex-polygon"/>.
        </t>

        <figure anchor="ex-polygon">
          <artwork><![CDATA[
  <gml:Polygon srsName="urn:ogc:def:crs:EPSG::4326">
    <gml:exterior>
      <gml:LinearRing>
        <gml:posList>
          -33.856625 151.215906 -33.856299 151.215343
          -33.856326 151.214731 -33.857533 151.214495
          -33.857720 151.214613 -33.857369 151.215375
          -33.856625 151.215906
        </gml:posList>
      </gml:LinearRing>
    </gml:exterior>
  </gml:Polygon>
]]></artwork>
        </figure>

        <t>
          To convert this to a polygon, each point is firstly assigned an altitude of zero and
          converted to ECEF coordinates (see <xref target="ecef2geo"/>).  Then a normal vector for
          this polygon is found (see <xref target="polygonupnormal"/>).  The result of each of these
          stages is shown in <xref target="ex-poly-convert"/>.  Note that the numbers shown in this
          document are rounded only for formatting reasons; the actual calculations do not include
          rounding, which would generate significant errors in the final values.
        </t>

        <figure anchor="ex-poly-convert">
          <artwork><![CDATA[
Polygon in ECEF coordinate space
   (repeated point omitted and transposed to fit):
         [ -4.6470e+06  2.5530e+06  -3.5333e+06 ]
         [ -4.6470e+06  2.5531e+06  -3.5332e+06 ]
 pecef = [ -4.6470e+06  2.5531e+06  -3.5332e+06 ]
         [ -4.6469e+06  2.5531e+06  -3.5333e+06 ]
         [ -4.6469e+06  2.5531e+06  -3.5334e+06 ]
         [ -4.6469e+06  2.5531e+06  -3.5333e+06 ]

Normal Vector: n = [ -0.72782  0.39987  -0.55712 ]

Transformation Matrix:
     [ -0.48152  -0.87643   0.00000 ]
 t = [ -0.48828   0.26827   0.83043 ]
     [ -0.72782   0.39987  -0.55712 ]

Transformed Coordinates:
          [  8.3206e+01  1.9809e+04  6.3715e+06 ]
          [  3.1107e+01  1.9845e+04  6.3715e+06 ]
 pecef' = [ -2.5528e+01  1.9842e+04  6.3715e+06 ]
          [ -4.7367e+01  1.9708e+04  6.3715e+06 ]
          [ -3.6447e+01  1.9687e+04  6.3715e+06 ]
          [  3.4068e+01  1.9726e+04  6.3715e+06 ]

Two dimensional polygon area: A = 12600 m^2
Two-dimensional polygon centroid: C' = [ 8.8184e+00  1.9775e+04 ]

Average of pecef' z coordinates: 6.3715e+06

Reverse Transformation Matrix:
      [ -0.48152  -0.48828  -0.72782 ]
 t' = [ -0.87643   0.26827   0.39987 ]
      [  0.00000   0.83043  -0.55712 ]

Polygon centroid (ECEF): C = [ -4.6470e+06  2.5531e+06  -3.5333e+06 ]
Polygon centroid (Geo): Cg = [ -33.856926  151.215102  -4.9537e-04 ]
]]></artwork>
        </figure>

        <t>
          The point conversion for the polygon uses the final result, <spanx
          style="verb">Cg</spanx>, ignoring the altitude since the original shape did not include
          altitude.
        </t>

        <t>
          To convert this to a circle, take the maximum distance in ECEF coordinates from the center
          point to each of the points.  This results in a radius of 99.1 meters.  Confidence is
          unchanged.
        </t>
      </section>

      <section title="Increasing and Decreasing Confidence">
        <t>
          Assume that confidence is known to be 19% for Alice's location information.  This is a
          typical value for a three-dimensional ellipsoid uncertainty of normal distribution where
          the standard deviation is used directly for uncertainty in each dimension.  The confidence
          associated with Alice's location estimate is quite low for many applications.  Since the
          estimate is known to follow a normal distribution, the method in <xref
          target="scale-normal"/> can be used.  Each axis can be scaled by:
          <list style="empty">
            <t>
              scale = erfinv(0.95^(1/3)) / erfinv(0.19^(1/3)) = 2.9937
            </t>
          </list>
          Ensuring that rounding always increases uncertainty, the location estimate at 95% includes
          a semi-major axis of 23.1, a semi-minor axis of 10 and a vertical axis of 86.
        </t>

        <t>
          Bob's location estimate (from the previous example) covers an area of approximately 12600
          square meters.  If the estimate follows a rectangular distribution, the region of
          uncertainty can be reduced in size.  Here we find the confidence that Bob is within the
          smaller area of the Concert Hall.  For the Concert Hall, the polygon
          [-33.856473,&nbsp;151.215257; -33.856322,&nbsp;151.214973; -33.856424,&nbsp;151.21471;
          -33.857248,&nbsp;151.214753; -33.857413,&nbsp;151.214941; -33.857311,&nbsp;151.215128] is
          used.  To use this new region of uncertainty, find its area using the same translation
          method described in <xref target="centroid-polygon"/>, which produces 4566.2 square
          meters.  Given that the Concert Hall is entirely within Bob's original location estimate,
          the confidence associated with the smaller area is therefore 95% * 4566.2 / 12600 = 34%.
        </t>
      </section>

      <section title="Matching Location Estimates to Regions of Interest">
        <t>
          Suppose that a circular area is defined centered at [-33.872754,&nbsp;151.20683] with a
          radius of 1950 meters.  To determine whether Bob is found within this area - given that
          Bob is at [-34.407242,&nbsp;150.882518] with an uncertainty radius 7.7156 meters - we
          apply the method in <xref target="inarea"/>.  Using the converted Circle shape for Bob's
          location, the distance between these points is found to be 1915.26 meters.  The area of
          overlap between Bob's location estimate and the region of interest is therefore 2209
          square meters and the area of Bob's location estimate is 30853 square meters.  This gives
          the estimated probability that Bob is less than 1950 meters from the selected point as
          67.8%.
        </t>

        <t>
          Note that if 1920 meters were chosen for the distance from the selected point, the area of
          overlap is only 16196 square meters and the confidence is 49.8%.  Therefore, it is
          marginally more likely that Bob is outside the region of interest, despite the center
          point of his location estimate being within the region.
        </t>

        <!-- TODO?: Need to show how choosing confidence can affect the outcome of a comparison result -->
      </section>


      <section title="PIDF-LO With Confidence Example">
        <t>
          The PIDF-LO document in <xref target="ex-conf"/> includes a representation of uncertainty
          as a circular area.  The confidence element (on the line marked with a comment) indicates
          that the confidence is 67% and that it follows a normal distribution.
        </t>

        <figure anchor="ex-conf" title="Example PIDF-LO with Confidence">
          <artwork><![CDATA[
  <pidf:presence
      xmlns:pidf="urn:ietf:params:xml:ns:pidf"
      xmlns:dm="urn:ietf:params:xml:ns:pidf:data-model"
      xmlns:gp="urn:ietf:params:xml:ns:pidf:geopriv10"
      xmlns:gs="http://www.opengis.net/pidflo/1.0"
      xmlns:gml="http://www.opengis.net/gml"
      xmlns:con="urn:ietf:params:xml:ns:geopriv:conf"
      entity="pres:alice@example.com">
    <dm:device id="sg89ab">
      <pidf:status>
        <gp:geopriv>
          <gp:location-info>
            <gs:Circle srsName="urn:ogc:def:crs:EPSG::4326">
              <gml:pos>42.5463 -73.2512</gml:pos>
              <gs:radius uom="urn:ogc:def:uom:EPSG::9001">
                850.24
              </gs:radius>
            </gs:Circle>
<!-- c -->  <con:confidence pdf="normal">67</con:confidence>
          </gp:location-info>
          <gp:usage-rules/>
        </gp:geopriv>
      </pidf:status>
      <dm:deviceID>mac:010203040506</dm:deviceID>
    </dm:device>
  </pidf:presence>
]]></artwork>
        </figure>
      </section>

    </section>

    <section anchor="schema" title="Confidence Schema">
      <figure><artwork><![CDATA[
<?xml version="1.0"?>
<xs:schema
    xmlns:conf="urn:ietf:params:xml:ns:geopriv:conf"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="urn:ietf:params:xml:ns:geopriv:conf"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

  <xs:annotation>
    <xs:appinfo
        source="urn:ietf:params:xml:schema:geopriv:conf">
      PIDF-LO Confidence
    </xs:appinfo>
    <xs:documentation source="http://www.ietf.org/rfc/rfcXXXX.txt">
      <!-- [[NOTE TO RFC-EDITOR: Please replace above URL with URL of
           published RFC and remove this note.]] -->
      This schema defines an element that is used for indicating
      confidence in PIDF-LO documents.
    </xs:documentation>
  </xs:annotation>

  <xs:element name="confidence" type="conf:confidenceType"/>

  <xs:complexType name="confidenceType">
    <xs:simpleContent>
      <xs:extension base="conf:confidenceBase">
        <xs:attribute name="pdf" type="conf:pdfType"
                      default="unknown"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:simpleType name="confidenceBase">
    <xs:union>
      <xs:simpleType>
        <xs:restriction base="xs:decimal">
          <xs:minExclusive value="0.0"/>
          <xs:maxExclusive value="100.0"/>
        </xs:restriction>
      </xs:simpleType>
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="unknown"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:union>
  </xs:simpleType>

  <xs:simpleType name="pdfType">
    <xs:restriction base="xs:token">
      <xs:enumeration value="unknown"/>
      <xs:enumeration value="normal"/>
      <xs:enumeration value="rectangular"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
]]></artwork></figure>
    </section>

    <section anchor="iana" title="IANA Considerations">
      <section title="URN Sub-Namespace Registration for urn:ietf:params:xml:ns:geopriv:conf">
        <t>
          This section registers a new XML namespace, <spanx
          style="verb">urn:ietf:params:xml:ns:geopriv:conf</spanx>, as per the guidelines in <xref
          target="RFC3688"/>.
          <list style="hanging">
            <t hangText="URI:">
              urn:ietf:params:xml:ns:geopriv:conf
            </t>
            <t hangText="Registrant Contact:">
              IETF, GEOPRIV working group, (geopriv@ietf.org), Martin Thomson
              (martin.thomson@gmail.com).
            </t>

            <t hangText="XML:">
              <figure>
                <artwork><![CDATA[
      BEGIN
        <?xml version="1.0"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
          <head>
            <title>PIDF-LO Confidence Attribute</title>
          </head>
          <body>
            <h1>Namespace for PIDF-LO Confidence Attribute</h1>
            <h2>urn:ietf:params:xml:ns:geopriv:conf</h2>
[[NOTE TO IANA/RFC-EDITOR: Please update RFC URL and replace XXXX
    with the RFC number for this specification.]]
            <p>See <a href="[[RFC URL]]">RFCXXXX</a>.</p>
          </body>
        </html>
      END
]]></artwork>
              </figure>
            </t>
          </list>
        </t>
      </section>

      <section title="XML Schema Registration">
        <t>
          This section registers an XML schema as per the guidelines in <xref target="RFC3688"/>.
          <list style="hanging">
            <t hangText="URI:">urn:ietf:params:xml:schema:geopriv:conf</t>
            <t hangText="Registrant Contact:">
              IETF, GEOPRIV working group, (geopriv@ietf.org), Martin Thomson
              (martin.thomson@gmail.com).
            </t>
            <t hangText="Schema:">
              The XML for this schema can be found as the entirety of <xref target="schema"/> of
              this document.
          </t>
        </list>
        </t>
      </section>

    </section>

    <section anchor="security" title="Security Considerations">
      <t>
        This document describes methods for managing and manipulating uncertainty in location.  No
        specific security concerns arise from most of the information provided.  The considerations
        of <xref target="RFC4119"/> all apply.
      </t>
      <t>
        A thorough treatment of the privacy implications of describing location information are
        discussed in <xref target="RFC6280"/>.  Including uncertainty information increases the
        amount of information available; and altering uncertainty is not an effective privacy
        mechanism.
      </t>
      <t>
        Providing uncertainty and confidence information can reveal information about the process by
        which location information is generated.  For instance, it might reveal information that
        could be used to infer that a user is using a mobile device with a GPS, or that a user is
        acquiring location information from a particular network-based service.  A Rule Maker might
        choose to remove uncertainty-related fields from a location object in order to protect this
        information.  Note however that information might not be perfectly protected due to
        difficulties associated with location obfuscation, as described in Section 13.5 of <xref
        target="RFC6772"/>.  In particular, increasing uncertainty does not necessarily result in a
        reduction of the information conveyed by the location object.
      </t>
      <t>
        Adding confidence to location information risks misinterpretation by consumers of location
        that do not understand the element.  This could be exploited, particularly when reducing
        confidence, since the resulting uncertainty region might include locations that are less
        likely to contain the target than the recipient expects.  Since this sort of error is always
        a possibility, the impact of this is low.
      </t>

    </section>

    <section anchor="ack" title="Acknowledgements">
      <t>
        Peter Rhodes provided assistance with some of the mathematical groundwork on this document.
        Dan Cornford provided a detailed review and many terminology corrections.
      </t>
    </section>

    <!--
        <appendix title="Change Log"> <t> [[The RFC Editor is requested to remove this section at
        publication.]]</t> <t> Changes since -0-1: <list style="symbols"> <t> Document created.</t>
        </list> </t> </appendix>
    -->
  </middle>

  <back>

    <references title="Normative References">
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3688.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3693.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.4119.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5139.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5491.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6225.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6280.xml"?>
    </references>

    <references title="Informative References">
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5222.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6772.xml"?>

      <reference anchor="TS-3GPP-23_032">
        <front>
          <title>Universal Geographic Area Description (GAD)</title>
          <author><organization>3GPP</organization></author>
          <date month="September" year="2012"/>
        </front>
        <seriesInfo name="3GPP TS" value="23.032 11.0.0"/>
        <format type="HTML" target="http://www.3gpp.org/ftp/Specs/html-info/23032.htm"/>
      </reference>

      <reference anchor="WGS84" target="">
        <front>
          <title>
            Department of Defense (DoD) World Geodetic System 1984 (WGS 84), Third Edition
          </title>
          <author fullname="">
            <organization>US National Imagery and Mapping Agency</organization>
          </author>
          <date day="3" month="January" year="2000"/>
        </front>
        <seriesInfo name="NIMA" value="TR8350.2"/>
      </reference>

      <reference anchor="GeoShape">
        <front>
          <title abbrev="Geo-Shape">GML 3.1.1 PIDF-LO Shape Application Schema for use by the
          Internet Engineering Task Force (IETF)</title>
          <author initials="M." surname="Thomson" fullname="Martin Thomson">
            <organization>Andrew Corporation</organization>
          </author>
          <author initials="C." surname="Reed" fullname="Carl Reed, PhD.">
            <organization>Open Geospatial Consortium Inc.</organization>
          </author>
          <date month="April" day="10" year="2007"/>
        </front>
        <seriesInfo name="Candidate OpenGIS Implementation Specification"
                    value="06-142r1, Version: 1.0"/>
      </reference>

      <reference anchor="ISO.GUM">
        <front>
          <title>
            Guide to the expression of uncertainty in measurement (GUM)
          </title>
          <author>
            <organization>ISO/IEC</organization>
          </author>
          <date year="1995"/>
        </front>
        <seriesInfo name="Guide" value="98:1995"/>
      </reference>

      <reference anchor="NIST.TN1297">
        <front>
          <title>
            Guidelines for Evaluating and Expressing the Uncertainty of NIST Measurement Results
          </title>
          <author initials="B." surname="Taylor" fullname="Barry N. Taylor">
            <organization>NIST</organization>
          </author>
          <author initials="C." surname="Kuyatt" fullname="Chris E. Kuyatt">
            <organization>NIST</organization>
          </author>
          <date month="Sep" year="1994"/>
        </front>
        <seriesInfo name="Technical Note" value="1297"/>
      </reference>

      <reference anchor="Convert">
        <front>
          <title>A Comparison of Methods Used in Rectangular to Geodetic Coordinate Transformations</title>
          <author initials="R." surname="Burtch" fullname="Robert Burtch">
            <organization>Ferris State University</organization>
          </author>
          <date month="April" year="2006"/>
        </front>
      </reference>

      <reference anchor="Sunday02" target="http://www.acm.org/jgt/papers/Sunday02/">
        <front>
          <title>
            Fast polygon area and Newell normal computation
          </title>
          <author initials="D" surname="Sunday" fullname="Daniel Sunday">
            <organization/>
          </author>
          <date year="2002"/>
        </front>
        <seriesInfo name="Journal of Graphics Tools" value="JGT, 7(2):9-13,2002"/>
      </reference>
      <reference anchor="Vatti92" target="http://portal.acm.org/citation.cfm?id=129906 ">
        <front>
          <title>
            A generic solution to polygon clipping
          </title>
          <author initials="B" surname="Vatti" fullname="Bala Vatti">
            <organization/>
          </author>
          <date year="1992"/>
        </front>
        <seriesInfo name="Communications of the ACM" value="Vol35, Issue7, pp56-63"/>
      </reference>
    </references>


    <section anchor="ecef2geo" title="Conversion Between Cartesian and Geodetic Coordinates in WGS84">
      <t>
        The process of conversion from geodetic (latitude, longitude and altitude) to
        earth-centered, earth-fixed (ECEF) Cartesian coordinates is relatively simple.
      </t>

      <t>
        In this section, the following constants and derived values are used from the definition of
        <xref target="WGS84">WGS84</xref>:
        <list style="empty">
          <t>
            {radius of ellipsoid} R = 6378137 meters
          </t>
          <t>
            {inverse flattening} 1/f = 298.257223563
          </t>
          <t>
            {first eccentricity squared} e^2 = f * (2 - f)
          </t>
          <t>
            {second eccentricity squared} e'^2 = e^2 * (1 - e^2)
          </t>
        </list>
      </t>

      <t>
        To convert geodetic coordinates (latitude, longitude, altitude) to ECEF coordinates (X, Y,
        Z), use the following relationships:
        <list style="empty">
          <t>
            N = R / sqrt(1 - e^2 * sin(latitude)^2)
          </t>
          <t>
            X = (N + altitude) * cos(latitude) * cos(longitude)
          </t>
          <t>
            Y = (N + altitude) * cos(latitude) * sin(longitude)
          </t>
          <t>
            Z = (N*(1 - e^2) + altitude) * sin(latitude)
          </t>
        </list>
      </t>

      <t>
        The reverse conversion requires more complex computation and most methods introduce some
        error in latitude and altitude.  A range of techniques are described in <xref
        target="Convert"/>.  A variant on the method originally proposed by Bowring, which results
        in an acceptably small error, is described by the following:
        <list style="empty">
          <t>
            p = sqrt(X^2 + Y^2)
          </t>
          <t>
            r = sqrt(X^2 + Y^2 + Z^2)
          </t>
          <t>
            u = atan((1-f) * Z * (1 + e'^2 * (1-f) * R / r) / p)
          </t>
          <t>
            latitude = atan((Z + e'^2 * (1-f) * R * sin(u)^3)
            /&nbsp;(p&nbsp;-&nbsp;e^2&nbsp;*&nbsp;R&nbsp;*&nbsp;cos(u)^3))
          </t>
          <t>
            longitude = atan2(Y, X)
          </t>
          <t>
            altitude = sqrt((p - R * cos(u))^2
            +&nbsp;(Z&nbsp;-&nbsp;(1-f)&nbsp;*&nbsp;R&nbsp;*&nbsp;sin(u))^2)
          </t>
        </list>
        If the point is near the poles, that is <spanx style="verb">p&nbsp;&lt;&nbsp;1</spanx>, the
        value for altitude that this method produces is unstable.  A simpler method for determining
        the altitude of a point near the poles is:
        <list style="empty">
          <t>
            altitude = |Z| - R * (1 - f)
          </t>
        </list>
      </t>
    </section>

    <section anchor="polygonupnormal" title="Calculating the Upward Normal of a Polygon">
      <t>
        For a polygon that is guaranteed to be convex and coplanar, the upward normal can be found
        by finding the vector cross product of adjacent edges.
      </t>

      <t>
        For more general cases the Newell method of approximation described in <xref
        target="Sunday02"/> may be applied.  In particular, this method can be used if the points
        are only approximately coplanar, and for non-convex polygons.
      </t>

      <t>
        This process requires a Cartesian coordinate system.  Therefore, <xref
        target="ecef2geo">convert the geodetic coordinates of the polygon to Cartesian, ECEF
        coordinates</xref>.  If no altitude is specified, assume an altitude of zero.
      </t>

      <t>
        This method can be condensed to the following set of equations:
        <list style="empty">
          <t>
            Nx = sum from i=1..n of (y[i] * (z[i+1] - z[i-1]))
          </t>
          <t>
            Ny = sum from i=1..n of (z[i] * (x[i+1] - x[i-1]))
          </t>
          <t>
            Nz = sum from i=1..n of (x[i] * (y[i+1] - y[i-1]))
          </t>
        </list>
        For these formulae, the polygon is made of points <spanx
        style="verb">(x[1],&nbsp;y[1],&nbsp;z[1])</spanx> through <spanx
        style="verb">(x[n],&nbsp;y[n],&nbsp;x[n])</spanx>.  Each array is treated as circular, that
        is, <spanx style="verb">x[0]&nbsp;==&nbsp;x[n]</spanx> and <spanx
        style="verb">x[n+1]&nbsp;==&nbsp;x[1]</spanx>.
      </t>

      <t>
        To translate this into a unit-vector; divide each component by the length of the vector:
        <list style="empty">
          <t>
            Nx' = Nx / sqrt(Nx^2 + Ny^2 + Nz^2)
          </t>
          <t>
            Ny' = Ny / sqrt(Nx^2 + Ny^2 + Nz^2)
          </t>
          <t>
            Nz' = Nz / sqrt(Nx^2 + Ny^2 + Nz^2)
          </t>
        </list>
      </t>

      <section anchor="polygonup" title="Checking that a Polygon Upward Normal Points Up">
        <t>
          <xref target="RFC5491">RFC 5491</xref> stipulates that polygons be presented in
          anti-clockwise direction so that the upward normal is in an upward direction.  Accidental
          reversal of points can invert this vector.  This error can be hard to detect just by
          looking at the series of coordinates that form the polygon.
        </t>

        <t>
          Calculate the dot product of the <xref target="polygonupnormal">upward normal of the
          polygon</xref> and any vector that points away from the center of the Earth from the
          location of polygon.  If this product is positive, then the polygon upward normal also
          points away from the center of the Earth.
          <list style="empty">
            <t>
              The inverse cosine of this value indicates the angle between the horizontal plane and
              the approximate plane of the polygon.
            </t>
          </list>
        </t>

        <t>
          A unit vector for the upward direction at any point can be found based on the latitude
          (lat) and longitude (lng) of the point, as follows:
        <list style="empty">
          <t>
          Up = [ cos(lat) * cos(lng) ; cos(lat) * sin(lng) ; sin(lat) ]</t>
        </list>
        </t>

        <t>
          For polygons that span less than half the globe, any point in the polygon - including the
          centroid - can be selected to generate an approximate up vector for comparison with the
          upward normal.
        </t>
      </section>
    </section>

  </back>
</rfc>
