Esempio n. 1
0
    /// <summary>
    /// Gets a new instance of <see cref="SurfaceRegion"/>.
    /// </summary>
    /// <param name="planet">The planet on which this region is found.</param>
    /// <param name="northLatitude">The latitude of the northwest corner of the region.</param>
    /// <param name="westLongitude">The longitude of the northwest corner of the region.</param>
    /// <param name="southLatitude">The latitude of the southeast corner of the region.</param>
    /// <param name="eastLongitude">The longitude of the southeast corner of the region.</param>
    /// <remarks>
    /// The region's actual size will be adjusted to ensure that the boundaries indicated would
    /// be fully displayed on both an equirectangular and a cylindrical equal-area projection of
    /// the region, which might result in a larger distance in one dimension than indicated by
    /// the given dimensions.
    /// </remarks>
    public static SurfaceRegion FromBounds(Planetoid planet, double northLatitude, double westLongitude, double southLatitude, double eastLongitude)
    {
        var latitudeRange      = Math.Abs(southLatitude - northLatitude);
        var centerLat          = northLatitude + (latitudeRange / 2);
        var longitudeRange     = Math.Abs(eastLongitude - westLongitude);
        var halfLongitudeRange = longitudeRange / 2;

        var position = planet.LatitudeAndLongitudeToVector(
            centerLat,
            westLongitude + halfLongitudeRange);

        latitudeRange = Math.Max(
            latitudeRange,
            halfLongitudeRange);
        var equalAreaAspectRatio = Math.PI * Math.Cos(centerLat).Square();

        latitudeRange = Math.Max(
            latitudeRange,
            longitudeRange / equalAreaAspectRatio);
        latitudeRange = Math.Min(
            latitudeRange,
            Math.PI);

        return(new SurfaceRegion(
                   planet,
                   position,
                   latitudeRange));
    }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of <see cref="SurfaceRegion"/>.
 /// </summary>
 /// <param name="planet">The planet on which this region is found.</param>
 /// <param name="latitude">The latitude of the center of the region.</param>
 /// <param name="longitude">The longitude of the center of the region.</param>
 /// <param name="latitudeRange">
 /// <para>
 /// The range of latitudes encompassed by this region, as an angle (in radians).
 /// </para>
 /// <para>
 /// Maximum value is π (a full hemisphere, which produces the full globe).
 /// </para>
 /// </param>
 public SurfaceRegion(Planetoid planet, double latitude, double longitude, HugeNumber latitudeRange)
     : base(planet.Id, new Frustum <HugeNumber>(2, planet.LatitudeAndLongitudeToVector(latitude, longitude) * (planet.Shape.ContainingRadius + planet.Atmosphere.AtmosphericHeight), HugeNumber.Min(latitudeRange, HugeNumber.Pi), 0))
 {
 }