90 || $lat < -90) throw new EBase('Out of Range!'); else $this->lat = (float) $lat; if ($lon > 90 || $lon < -90) throw new EBase('Out of Range!'); else $this->lon = (float) $lon; $this->alt = (float) $alt; } /** * @brief calculates distance between two coordinates * @param $to * @link http://williams.best.vwh.net/avform.htm * @since 33 * @return float distance in kilometers to $pos */ function distance(TLatLon $to) { return 6371.01 * $this->greatCircleDistance($to); } /** * @brief calculates course between two coordinates * @param $to * @link http://williams.best.vwh.net/avform.htm * @since 33 * @return float course in degree oriented towards the true northpole */ function course(TLatLon $to) { $lat1 = deg2rad($this->lat); $lon1 = deg2rad($this->lon); $lat2 = deg2rad($to->lat); $lon2 = deg2rad($to->lon); $d = $this->greatCircleDistance($to); $course = acos((sin($lat2) - sin($lat1) * cos($d)) / (sin($d) * cos($lat1))); if (sin($lon2 - $lon1) < 0) { $course = 2 * pi() - $course; } return rad2deg($course); } /** * @brief calculates human readable course information * @param $to * @since 33 * @return string */ function courseLetters($to) { //TODO added windroses for diffrent languages $windrose = array('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'); $angle = $this->course($to); return $windrose[round($angle / 45)]; } /** * @brief calculates the angle between the two coordinates and the earth's centerpoint * @param $to * @since 33 * @return float great circle distance in radians */ private function greatCircleDistance(TLatLon $to) { $lat1 = deg2rad($this->lat); $lon1 = deg2rad($this->lon); $lat2 = deg2rad($to->lat); $lon2 = deg2rad($to->lon); return acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lon2 - $lon1)); } } class TTrack { public $coords = array(); function __construct($start, $end) { } /** * @brief calculate length of the line * @return float length in kilometers */ function length() { } } class TPolygon { public $points; // of TLatLon } ?>