@@ -144,6 +144,7 @@ def __init__(self, name, radius_m, inverse_flattening):
144144 self ._one_minus_flattening_squared = omf * omf
145145 f = 1.0 / inverse_flattening
146146 self ._e2 = 2.0 * f - f * f
147+ self .semi_minor_axis = Distance (m = radius_m * (1.0 - f ))
147148
148149 def latlon (self , latitude_degrees , longitude_degrees , elevation_m = 0.0 ,
149150 cls = GeographicPosition ):
@@ -211,7 +212,10 @@ def height_of(self, position):
211212
212213 """
213214 xyz_au , x , y , aC , R , lat = self ._compute_latitude (position )
214- height_au = R / cos (lat ) - aC
215+ if R > 0.0 :
216+ height_au = R / cos (lat ) - aC
217+ else :
218+ height_au = abs (xyz_au [2 ]) - self .semi_minor_axis .au
215219 return Distance (height_au )
216220
217221 def geographic_position_of (self , position ):
@@ -225,7 +229,10 @@ def geographic_position_of(self, position):
225229 """
226230 xyz_au , x , y , aC , R , lat = self ._compute_latitude (position )
227231 lon = (arctan2 (y , x ) - pi ) % tau - pi
228- height_au = R / cos (lat ) - aC
232+ if R > 0.0 :
233+ height_au = R / cos (lat ) - aC
234+ else :
235+ height_au = abs (xyz_au [2 ]) - self .semi_minor_axis .au
229236 return GeographicPosition (
230237 latitude = Angle (radians = lat ),
231238 longitude = Angle (radians = lon ),
0 commit comments