public virtual void translate(Distance dist, IDirection dir) { double distMeters = dist.Meters; double dTheta = -DirectionMath.toRad(dir.bearing.Value); // radians; theta is positive to left, bearing - positive to right this.translate(distMeters * Math.Cos(dTheta), distMeters * Math.Sin(dTheta)); }
public Direction dir; // straight forward is 0, right is positive public RelPosition(Direction direction, Distance distance) { this.dir = (Direction)direction.Clone(); this.dist = (Distance)distance.Clone(); if (direction.bearingRelative.HasValue) { double bearingRad = DirectionMath.toRad(direction.bearingRelative.Value); X = distance.Meters * Math.Sin(bearingRad); Y = -distance.Meters * Math.Cos(bearingRad); } else if (direction.bearing.HasValue) { double bearingRad = DirectionMath.toRad(direction.bearing.Value); X = distance.Meters * Math.Sin(bearingRad); Y = -distance.Meters * Math.Cos(bearingRad); } }
public Distance distanceFrom(IGeoPosition from) { // here is a version that is lighter computationally and works well over miles of distance. // compared to distanceFromExact() the difference is 1mm per meter (0.1%) double x = m_X - from.Lng; //double x = this.subtract(from, false).m_X; double y = m_Y - from.Lat; //double y = this.subtract(from, false).m_Y; // a grad square is cos(latitude) thinner, we need latitude in radians: double midLatRad = ((from.Lat + m_Y) / 2.0d) * Math.PI / 180.0d; //double midLatRad = (this.add(from).m_Y / 2.0d) * Math.PI / 180.0d; double latitudeFactor = Math.Cos(midLatRad); double xMeters = Distance.METERS_PER_DEGREE * x * latitudeFactor; double yMeters = Distance.METERS_PER_DEGREE * y; double meters = Math.Sqrt(xMeters * xMeters + yMeters * yMeters); Distance distance = new Distance(meters); return distance; }
public string heightToString() { string height = ""; if(m_H > 0.3d) // meters { Distance d = new Distance(m_H); height = " " + d.ToStringCompl() + " high"; } else if(m_H < -0.3d) // meters { Distance d = new Distance(-m_H); height = " " + d + " deep"; } return height; }
public Distance distanceFromExact(IGeoPosition from) { // from http://www.movable-type.co.uk/scripts/LatLong.html double lon1 = this.Lng * Math.PI / 180.0d; double lon2 = from.Lng * Math.PI / 180.0d; double lat1 = this.Lat * Math.PI / 180.0d; double lat2 = from.Lat * Math.PI / 180.0d; double dLat = lat2 - lat1; double dLong = lon2 - lon1; double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Sin(dLong / 2) * Math.Sin(dLong / 2); double c = 2.0d * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0d - a)); double meters = EARTH_RADIUS * c; Distance distance = new Distance(meters); return distance; }