Skip to content

Commit

Permalink
feat: FromLLA constructor for position (#305)
Browse files Browse the repository at this point in the history
* feat: FromLLA constructor for position

* chore: style

* feat: lla FromPosition constructor (#306)

* feat: Add FromPosition static constructor to LLA class

* feat: Add FromPosition test case for LLA coordinate conversion

* feat: Add FromPosition method tests for LLA Python bindings

* test: Add FromPosition test for LLA coordinate conversion

* feat: add tests for from position
vishwa2710 authored Jan 6, 2025
1 parent adc06d4 commit bce5d2a
Showing 11 changed files with 395 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
arg("unit"),
arg("frame"),
R"doc(
Constructs a position.
Constructs a Position.
Args:
coordinates (np.ndarray): Coordinates.
@@ -43,7 +43,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
Equality operator.
Args:
other (Position): Other position.
other (Position): Other Position.
Returns:
bool: True if equal.
@@ -55,7 +55,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
Inequality operator.
Args:
other (Position): Other position.
other (Position): Other Position.
Returns:
bool: True if not equal.
@@ -126,7 +126,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
"in_unit",
&Position::inUnit,
R"doc(
Get the position in the unit.
Get the Position in the unit.
Returns:
Position: Position in the unit.
@@ -136,7 +136,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
"in_meters",
&Position::inMeters,
R"doc(
Get the position in meters.
Get the Position in meters.
Returns:
Position: Position in meters.
@@ -148,7 +148,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
arg("frame"),
arg("instant"),
R"doc(
Get the position in another frame of reference.
Get the Position in another frame of reference.
Args:
frame (Frame): Frame of reference.
@@ -177,10 +177,10 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
"undefined",
&Position::Undefined,
R"doc(
Get undefined position.
Get undefined Position.
Returns:
Position: Undefined position.
Position: Undefined Position.
)doc"
)
.def_static(
@@ -189,7 +189,7 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
arg("coordinates"),
arg("frame"),
R"doc(
Create a position in meters.
Create a Position in meters.
Args:
coordinates (np.ndarray): Coordinates.
@@ -199,6 +199,22 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Position(pybind11::module& aMod
Position: Position in meters.
)doc"
)
.def_static(
"from_lla",
&Position::FromLLA,
arg("lla"),
arg("celestial") = nullptr,
R"doc(
Create a Position from LLA.
Args:
lla (LLA): LLA.
celestial_object (Celestial): Celestial object. Defaults to None. If None, the central body from the global environment instance will be used if it's available.
Returns:
Position: Position.
)doc"
)

;
}
Original file line number Diff line number Diff line change
@@ -414,6 +414,22 @@ inline void OpenSpaceToolkitPhysicsPy_Coordinate_Spherical_LLA(pybind11::module&
arg_v("ellipsoid_equatorial_radius", Length::Undefined(), "Length.Undefined()"),
arg_v("ellipsoid_flattening", Real::Undefined(), "Real.Undefined()")
)
.def_static(
"from_position",
&LLA::FromPosition,
R"doc(
Construct LLA from position.
Args:
position (Position): Position.
celestial (Celestial): Celestial object. Defaults to None, in which case, values from the global Environment central celestial are used.
Returns:
LLA: LLA.
)doc",
arg("position"),
arg_v("celestial", nullptr, "None")
)

;
}
24 changes: 24 additions & 0 deletions bindings/python/test/coordinate/spherical/test_lla.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,9 @@
from ostk.physics import Environment
from ostk.physics.unit import Angle, Length
from ostk.physics.coordinate.spherical import LLA
from ostk.physics.coordinate import Frame, Position
from ostk.physics.environment.gravitational import Earth as EarthGravitationalModel
from ostk.physics.environment.object.celestial import Earth

Spherical = EarthGravitationalModel.spherical
WGS84_EGM96 = EarthGravitationalModel.WGS84_EGM96
@@ -488,3 +490,25 @@ def test_linspace(
)
assert llas is not None
assert len(llas) == n_points

def test_from_position(self):
earth = Earth.WGS84()
frame = Frame.ITRF()
position = Position.meters([6378137.0, 0.0, 0.0], frame) # Point on equator

lla = LLA.from_position(position, earth)
assert lla is not None
assert abs(float(lla.get_latitude().in_degrees())) < 1e-10 # Should be on equator

assert (
abs(float(lla.get_longitude().in_degrees())) < 1e-10
) # Should be at prime meridian
assert abs(float(lla.get_altitude().in_meters())) < 1e-6 # Should be near surface

# Test with undefined position
with pytest.raises(RuntimeError):
LLA.from_position(Position.undefined())

# Test with global environment
lla = LLA.from_position(position)
assert lla is not None
Loading

0 comments on commit bce5d2a

Please sign in to comment.