public static ToRadians ( double degrees ) : double | ||
degrees | double | |
return | double |
public override Point PointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse) { if (distDEG == 0) { if (reuse == null) { return(from); } reuse.Reset(from.GetX(), from.GetY()); return(reuse); } double bearingRAD = DistanceUtils.ToRadians(bearingDEG); double x = from.GetX() + Math.Sin(bearingRAD) * distDEG; double y = from.GetY() + Math.Cos(bearingRAD) * distDEG; if (reuse == null) { return(ctx.MakePoint(x, y)); } else { reuse.Reset(x, y); return(reuse); } }
public override double Area(Circle circle) { //formula is a simplified case of area(rect). double lat = DistanceUtils.ToRadians(90 - circle.GetRadius()); return(2 * Math.PI * radiusDEG * radiusDEG * (1 - Math.Sin(lat))); }
public override double Area(Rectangle rect) { //From http://mathforum.org/library/drmath/view/63767.html double lat1 = DistanceUtils.ToRadians(rect.GetMinY()); double lat2 = DistanceUtils.ToRadians(rect.GetMaxY()); return(Math.PI / 180 * radiusDEG * radiusDEG * Math.Abs(Math.Sin(lat1) - Math.Sin(lat2)) * rect.GetWidth()); }
/// <summary> /// Calculates the degrees longitude distance at latitude <paramref name="lat"/> to cover /// a distance <paramref name="dist"/>. /// <para> /// Used to calculate a new expanded buffer distance to account for skewing /// effects for shapes that use the lat-lon space as a 2D plane instead of a /// sphere. The expanded buffer will be sure to cover the intended area, but /// the shape is still skewed and so it will cover a larger area. For latitude /// 0 (the equator) the result is the same buffer. At 60 (or -60) degrees, the /// result is twice the buffer, meaning that a shape at 60 degrees is twice as /// high as it is wide when projected onto a lat-lon plane even if in the real /// world it's equal all around. /// </para> /// If the result added to abs(<paramref name="lat"/>) is >= 90 degrees, then skewing is /// so severe that the caller should consider tossing the shape and /// substituting a spherical cap instead. /// </summary> /// <param name="lat">latitude in degrees</param> /// <param name="dist">distance in degrees</param> /// <returns>longitudinal degrees (x delta) at input latitude that is >= /// <paramref name="dist"/> distance. Will be >= dist and <= 90.</returns> public static double CalcLonDegreesAtLat(double lat, double dist) { //This code was pulled out of DistanceUtils.pointOnBearingRAD() and // optimized // for bearing = 90 degrees, and so we can get an intermediate calculation. double distanceRAD = DistanceUtils.ToRadians(dist); double startLat = DistanceUtils.ToRadians(lat); double cosAngDist = Math.Cos(distanceRAD); double cosStartLat = Math.Cos(startLat); double sinAngDist = Math.Sin(distanceRAD); double sinStartLat = Math.Sin(startLat); double lonDelta = Math.Atan2(sinAngDist * cosStartLat, cosAngDist * (1 - sinStartLat * sinStartLat)); return(DistanceUtils.ToDegrees(lonDelta)); }
private readonly double radiusDEG = DistanceUtils.ToDegrees(1); //in degrees public override Point PointOnBearing(Point @from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse) { if (distDEG == 0) { if (reuse == null) { return(from); } reuse.Reset(from.GetX(), from.GetY()); return(reuse); } Point result = DistanceUtils.PointOnBearingRAD( DistanceUtils.ToRadians(from.GetY()), DistanceUtils.ToRadians(from.GetX()), DistanceUtils.ToRadians(distDEG), DistanceUtils.ToRadians(bearingDEG), ctx, reuse);//output result is in radians result.Reset(DistanceUtils.ToDegrees(result.GetX()), DistanceUtils.ToDegrees(result.GetY())); return(result); }
public override double Distance(Point @from, double toX, double toY) { return(DistanceUtils.ToDegrees(DistanceLatLonRAD(DistanceUtils.ToRadians(from.GetY()), DistanceUtils.ToRadians(from.GetX()), DistanceUtils.ToRadians(toY), DistanceUtils.ToRadians(toX)))); }