Skip to content

Commit

Permalink
feat: add Euler Angle class
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-bremond committed Jun 10, 2024
1 parent ab8d09b commit 04274fc
Show file tree
Hide file tree
Showing 48 changed files with 4,759 additions and 887 deletions.
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::phi)
.def_property_readonly("theta", &EulerAngle::theta)
.def_property_readonly("psi", &EulerAngle::psi)
.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 @@ -55,6 +55,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,7 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_Angle(pybind11::module& aModu

.def("is_defined", &Angle::isDefined)
.def("is_zero", &Angle::isZero)
.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 04274fc

Please sign in to comment.