@@ 111-157 (lines=47) @@ | ||
108 | * |
|
109 | * @return number |
|
110 | */ |
|
111 | protected function getPerpendicularDistance(Coordinate $point, Line $line) |
|
112 | { |
|
113 | $ellipsoid = $point->getEllipsoid(); |
|
114 | ||
115 | $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius(); |
|
116 | ||
117 | $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat()); |
|
118 | $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng()); |
|
119 | ||
120 | $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat); |
|
121 | $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat); |
|
122 | $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat); |
|
123 | ||
124 | $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat()); |
|
125 | $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng()); |
|
126 | ||
127 | $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat); |
|
128 | $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat); |
|
129 | $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat); |
|
130 | ||
131 | $pointLat = $this->deg2radLatitude($point->getLat()); |
|
132 | $pointLng = $this->deg2radLongitude($point->getLng()); |
|
133 | ||
134 | $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat); |
|
135 | $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat); |
|
136 | $pointZ = $ellipsoidRadius * cos($pointLat); |
|
137 | ||
138 | $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY; |
|
139 | $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ; |
|
140 | $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX; |
|
141 | ||
142 | $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ); |
|
143 | ||
144 | $normalizedX /= $length; |
|
145 | $normalizedY /= $length; |
|
146 | $normalizedZ /= $length; |
|
147 | ||
148 | $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ; |
|
149 | ||
150 | $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ); |
|
151 | ||
152 | $thetaPoint /= $length; |
|
153 | ||
154 | $distance = abs((M_PI / 2) - acos($thetaPoint)); |
|
155 | ||
156 | return $distance * $ellipsoidRadius; |
|
157 | } |
|
158 | ||
159 | /** |
|
160 | * @param float $latitude |
@@ 103-149 (lines=47) @@ | ||
100 | * |
|
101 | * @return number |
|
102 | */ |
|
103 | protected function getPerpendicularDistance(Coordinate $point, Line $line) |
|
104 | { |
|
105 | $ellipsoid = $point->getEllipsoid(); |
|
106 | ||
107 | $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius(); |
|
108 | ||
109 | $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat()); |
|
110 | $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng()); |
|
111 | ||
112 | $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat); |
|
113 | $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat); |
|
114 | $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat); |
|
115 | ||
116 | $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat()); |
|
117 | $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng()); |
|
118 | ||
119 | $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat); |
|
120 | $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat); |
|
121 | $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat); |
|
122 | ||
123 | $pointLat = $this->deg2radLatitude($point->getLat()); |
|
124 | $pointLng = $this->deg2radLongitude($point->getLng()); |
|
125 | ||
126 | $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat); |
|
127 | $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat); |
|
128 | $pointZ = $ellipsoidRadius * cos($pointLat); |
|
129 | ||
130 | $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY; |
|
131 | $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ; |
|
132 | $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX; |
|
133 | ||
134 | $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ); |
|
135 | ||
136 | $normalizedX /= $length; |
|
137 | $normalizedY /= $length; |
|
138 | $normalizedZ /= $length; |
|
139 | ||
140 | $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ; |
|
141 | ||
142 | $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ); |
|
143 | ||
144 | $thetaPoint /= $length; |
|
145 | ||
146 | $distance = abs((M_PI / 2) - acos($thetaPoint)); |
|
147 | ||
148 | return $distance * $ellipsoidRadius; |
|
149 | } |
|
150 | ||
151 | /** |
|
152 | * @param float $latitude |