Skip to content

Commit

Permalink
feat: add Euler Angle class (#129)
Browse files Browse the repository at this point in the history
* feat: add Euler Angle class
* fix: python tests
  • Loading branch information
lucas-bremond authored Jun 11, 2024
1 parent ab8d09b commit c836728
Show file tree
Hide file tree
Showing 57 changed files with 12,388 additions and 895 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,11 @@ test-unit-python-standalone: ## Run Python unit tests (standalone)
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_PYTHON_BINDINGS=ON -DBUILD_UNIT_TESTS=OFF .. \
&& $(MAKE) -j 4 && python3.11 -m pip install --root-user-action=ignore bindings/python/OpenSpaceToolkit*Py-python-package-3.11 \
&& python3.11 -m pip install plotly pandas \
&& cd /usr/local/lib/python3.11/site-packages/ostk/$(project_name)/ \
&& python3.11 -m pytest -sv ."
&& $(MAKE) -j 4 \
&& python$(jupyter_python_version) -m pip install --root-user-action=ignore bindings/python/OpenSpaceToolkit*Py-python-package-$(jupyter_python_version) \
&& python$(jupyter_python_version) -m pip install plotly pandas \
&& cd /usr/local/lib/python$(jupyter_python_version)/dist-packages/ostk/$(project_name)/ \
&& python$(jupyter_python_version) -m pytest -sv ."

.PHONY: test-unit-python-standalone

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ inline void OpenSpaceToolkitMathematicsPy_CurveFitting(pybind11::module& aModule
// Create "curve fitting" python submodule
auto curve_fitting = aModule.def_submodule("curve_fitting");


// Add object to python "interpolators" submodules
OpenSpaceToolkitMathematicsPy_CurveFitting_Interpolator(curve_fitting);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ inline void OpenSpaceToolkitMathematicsPy_CurveFitting_Interpolator(pybind11::mo
// Create "interpolator" python submodule
auto interpolator = aModule.def_submodule("interpolator");


// Add object to python "interpolator" submodules
OpenSpaceToolkitMathematicsPy_CurveFitting_Interpolator_BarycentricRational(interpolator);
OpenSpaceToolkitMathematicsPy_CurveFitting_Interpolator_CubicSpline(interpolator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry(pybind11::module& aModule)
// Create "geometry" python submodule
auto geometry = aModule.def_submodule("geometry");


// Add object to python "geometry" submodules
OpenSpaceToolkitMathematicsPy_Geometry_2D(geometry);
OpenSpaceToolkitMathematicsPy_Geometry_3D(geometry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_2D(pybind11::module& aModule)
// Create "d2" python submodule
auto d2 = aModule.def_submodule("d2");


// Add object to python "d2" submodules
OpenSpaceToolkitMathematicsPy_Geometry_2D_Object(d2);
OpenSpaceToolkitMathematicsPy_Geometry_2D_Transformation(d2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_2D_Object(pybind11::module &a
// Create "object" python submodule
auto object = aModule.def_submodule("object");


// Add object to python "object" submodules
OpenSpaceToolkitMathematicsPy_Geometry_2D_Object_Point(object);
OpenSpaceToolkitMathematicsPy_Geometry_2D_Object_PointSet(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D(pybind11::module& aModule)
// Create "d3" python submodule
auto d3 = aModule.def_submodule("d3");


// Add object to python "d3" submodules
OpenSpaceToolkitMathematicsPy_Geometry_3D_Object(d3);
OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation(d3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Object(pybind11::module& a
// Create "object" python submodule
auto object = aModule.def_submodule("object");


// Add object to python "object" submodules
OpenSpaceToolkitMathematicsPy_Geometry_3D_Object_Point(object);
OpenSpaceToolkitMathematicsPy_Geometry_3D_Object_PointSet(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation(pybind11::m
// Create "transformation" python submodule
auto transformation_module = aModule.def_submodule("transformation");


// Add object to python "transformation" submodules
OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation(transformation_module);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Apache License 2.0

#include <OpenSpaceToolkitMathematicsPy/Geometry/3D/Transformation/Rotation/EulerAngle.cpp>
#include <OpenSpaceToolkitMathematicsPy/Geometry/3D/Transformation/Rotation/Quaternion.cpp>
#include <OpenSpaceToolkitMathematicsPy/Geometry/3D/Transformation/Rotation/RotationMatrix.cpp>
#include <OpenSpaceToolkitMathematicsPy/Geometry/3D/Transformation/Rotation/RotationVector.cpp>
Expand All @@ -9,9 +10,9 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation(py
// Create "rotation" python submodule
auto rotation = aModule.def_submodule("rotation");


// Add object to python "rotation" submodules
OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_Quaternion(rotation);
OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_RotationVector(rotation);
OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_RotationMatrix(rotation);
OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_EulerAngle(rotation);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/// Apache License 2.0

#include <OpenSpaceToolkit/Mathematics/Geometry/3D/Transformation/Rotation/EulerAngle.hpp>
#include <OpenSpaceToolkit/Mathematics/Geometry/3D/Transformation/Rotation/Quaternion.hpp>
#include <OpenSpaceToolkit/Mathematics/Geometry/3D/Transformation/Rotation/RotationMatrix.hpp>
#include <OpenSpaceToolkit/Mathematics/Geometry/Angle.hpp>

inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_EulerAngle(pybind11::module& aModule)
{
using namespace pybind11;

using ostk::core::type::Real;
using ostk::core::type::String;

using ostk::mathematics::object::Vector3d;
using ostk::mathematics::geometry::Angle;
using ostk::mathematics::geometry::d3::transformation::rotation::EulerAngle;

class_<EulerAngle> eulerAngle(aModule, "EulerAngle");

eulerAngle
// Define constructor
.def(
init<const Angle&, const Angle&, const Angle&, const EulerAngle::AxisSequence&>(),
arg("phi"),
arg("theta"),
arg("psi"),
arg("axis_sequence")
)
.def(
init<const Vector3d&, const Angle::Unit&, const EulerAngle::AxisSequence&>(),
arg("vector"),
arg("angle_unit"),
arg("axis_sequence")
)

// Define methods
.def(self == self)
.def(self != self)

.def("__str__", &(shiftToString<EulerAngle>))
.def("__repr__", &(shiftToString<EulerAngle>))

.def("is_defined", &EulerAngle::isDefined)
.def("is_unitary", &EulerAngle::isUnitary)
.def("is_near", &EulerAngle::isNear, arg("euler_angle"), arg("angular_tolerance"))

.def_property_readonly("phi", &EulerAngle::getPhi)
.def_property_readonly("theta", &EulerAngle::getTheta)
.def_property_readonly("psi", &EulerAngle::getPsi)
.def_property_readonly("axis_sequence", &EulerAngle::getAxisSequence)

.def("to_vector", &EulerAngle::toVector, arg("angle_unit"))
.def(
"to_string",
+[](const EulerAngle& aEulerAngle) -> String
{
return aEulerAngle.toString();
}
)
.def(
"to_string",
+[](const EulerAngle& aEulerAngle, const Angle::Unit& anAngleUnit) -> String
{
return aEulerAngle.toString(anAngleUnit);
},
arg("angle_unit")
)

// Define static methods
.def_static("undefined", &EulerAngle::Undefined)
.def_static("unit", &EulerAngle::Unit)
.def_static("xyz", &EulerAngle::XYZ, arg("phi"), arg("theta"), arg("psi"))
.def_static("zxy", &EulerAngle::ZXY, arg("phi"), arg("theta"), arg("psi"))
.def_static("zyx", &EulerAngle::ZYX, arg("phi"), arg("theta"), arg("psi"))
.def_static("quaternion", &EulerAngle::Quaternion, arg("quaternion"), arg("axis_sequence"))
.def_static("rotation_vector", &EulerAngle::RotationVector, arg("rotation_vector"), arg("axis_sequence"))
.def_static("rotation_matrix", &EulerAngle::RotationMatrix, arg("rotation_matrix"), arg("axis_sequence"))

;

enum_<EulerAngle::AxisSequence>(eulerAngle, "AxisSequence")

.value("Undefined", EulerAngle::AxisSequence::Undefined)
.value("XYZ", EulerAngle::AxisSequence::XYZ)
.value("ZXY", EulerAngle::AxisSequence::ZXY)
.value("ZYX", EulerAngle::AxisSequence::ZYX)

;
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_Qu
)
.def_static("rotation_vector", &Quaternion::RotationVector, arg("rotation_vector"))
.def_static("rotation_matrix", &Quaternion::RotationMatrix, arg("rotation_matrix"))
.def_static("euler_angle", &Quaternion::EulerAngle, arg("euler_angle"))
.def_static("parse", &Quaternion::Parse, arg("string"), arg("format"))
.def_static("shortest_rotation", &Quaternion::ShortestRotation, arg("first_vector"), arg("second_vector"))
.def_static("lerp", &Quaternion::LERP, arg("first_quaternion"), arg("second_quaternion"), arg("ratio"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_Ro
.def_static("columns", &RotationMatrix::Columns, arg("first_column"), arg("second_column"), arg("third_column"))
.def_static("quaternion", &RotationMatrix::Quaternion, arg("quaternion"))
.def_static("rotation_vector", &RotationMatrix::RotationVector, arg("rotation_vector"))
.def_static("euler_angle", &RotationMatrix::EulerAngle, arg("euler_angle"))

;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_Ro

// Define constructor
.def(init<const Vector3d&, const Angle&>(), arg("axis"), arg("angle"))
.def(init<const Vector3d&, const Angle::Unit&>(), arg("vector"), arg("angle_unit"))

// Define methods
.def(self == self)
Expand Down Expand Up @@ -47,6 +48,14 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_Ro
}
)

.def(
"rectify",
+[](RotationVector& aRotationVector) -> void
{
aRotationVector.rectify();
}
)

// Define static methods
.def_static("undefined", &RotationVector::Undefined)
.def_static("unit", &RotationVector::Unit)
Expand All @@ -55,6 +64,7 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Transformation_Rotation_Ro
.def_static("z", &RotationVector::Z, arg("angle"))
.def_static("quaternion", &RotationVector::Quaternion, arg("quaternion"))
.def_static("rotation_matrix", &RotationVector::RotationMatrix, arg("rotation_matrix"))
.def_static("euler_angle", &RotationVector::EulerAngle, arg("euler_angle"))

;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_Angle(pybind11::module& aModu

.def("is_defined", &Angle::isDefined)
.def("is_zero", &Angle::isZero)
.def("is_negative", &Angle::isNegative)
.def("is_near", &Angle::isNear, arg("angle"), arg("tolerance"))

.def("get_unit", &Angle::getUnit)
.def("in_unit", &Angle::in, arg("unit"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ inline void OpenSpaceToolkitMathematicsPy_Object(pybind11::module& aModule)
// Create "object" python submodule
auto object = aModule.def_submodule("object");


// Add object to python "object" submodules
OpenSpaceToolkitMathematicsPy_Object_Interval(object);
// OpenSpaceToolkitMathematicsPy_Object_Vector(object) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ inline void OpenSpaceToolkitMathematicsPy_Solver(pybind11::module& aModule)
// Create "object" python submodule
auto solver = aModule.def_submodule("solver");


// Add object to python "interpolators" submodules
OpenSpaceToolkitMathematicsPy_Solver_NumericalSolver(solver);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def interpolator() -> BarycentricRational:


class TestBarycentricRational:
def test_constructors(self, interpolator: BarycentricRational):
def test_constructor_success(self, interpolator: BarycentricRational):
assert interpolator is not None
assert isinstance(interpolator, Interpolator)
assert isinstance(interpolator, BarycentricRational)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def interpolator() -> CubicSpline:


class TestCubicSpline:
def test_constructors(self, interpolator: CubicSpline):
def test_constructor_success(self, interpolator: CubicSpline):
assert interpolator is not None
assert isinstance(interpolator, Interpolator)
assert isinstance(interpolator, CubicSpline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ def interpolator() -> Linear:


class TestLinear:
def test_constructors(self, interpolator: Linear):
def test_constructor_success(self, interpolator: Linear):
assert interpolator is not None
assert isinstance(interpolator, Interpolator)
assert isinstance(interpolator, Linear)


def test_evaluate(self):
interpolator = Linear(
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
Expand Down
4 changes: 3 additions & 1 deletion bindings/python/test/geometry/d3/object/test_linestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def test_constructor_success(self):
assert linestring.is_defined()

# Construction with Array of Points using python numpy array
linestring: LineString = LineString(np.array((point_1, point_2, point_3, point_4)))
linestring: LineString = LineString(
np.array((point_1, point_2, point_3, point_4))
)

assert linestring is not None
assert isinstance(linestring, LineString)
Expand Down
Loading

0 comments on commit c836728

Please sign in to comment.