Ejemplo n.º 1
0
        /// <summary>
        ///     Calculates the largest dimension (width or height) of the terrain slice
        ///     enclosed by the bounding box if the terrain slice is rotated such that
        ///     the median direction is pointing upwards in world space. Currently only
        ///     works with restricted (total longitude <= 180°) bounding boxes.
        /// </summary>
        public static float LargestDimension(BoundingBox boundingBox, float radius = 1.0f)
        {
            float width, height, lat;

            // If the latitudes are on opposite sides, then we need to
            // calculate the width at the equator.
            if (boundingBox[1] * boundingBox[3] < 0)
            {
                lat = 0.0f;
            }

            // Else, use the latitude closest to the equator to calculate the width.
            else
            {
                lat = Mathf.Min(Mathf.Abs(boundingBox[1]), Mathf.Max(boundingBox[3]));
            }

            // Calculate the width.
            width = Vector3.Distance(
                CoordinateUtils.LatLonToPosition(new Vector2(lat, boundingBox[0]), radius),
                CoordinateUtils.LatLonToPosition(new Vector2(lat, boundingBox[2]), radius)
                );

            // Height should be calculated at the median longitude.
            float lon = (boundingBox[0] + boundingBox[2]) / 2;

            // Calculate the height.
            height = Vector3.Distance(
                CoordinateUtils.LatLonToPosition(new Vector2(boundingBox[1], lon), radius),
                CoordinateUtils.LatLonToPosition(new Vector2(boundingBox[3], lon), radius)
                );

            return(Mathf.Max(width, height));
        }
Ejemplo n.º 2
0
        public static Vector3 MedianDirection(BoundingBox boundingBox)
        {
            Vector2 medianLatLong = MedianLatLon(boundingBox);

            return(CoordinateUtils.LatLonToDirection(medianLatLong));
        }