Antkeeper  0.0.1
se3.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_MATH_TRANSFORMATION_SE3_HPP
21 #define ANTKEEPER_MATH_TRANSFORMATION_SE3_HPP
22 
23 #include <engine/math/vector.hpp>
25 
26 namespace math {
27 
33 template <class T>
34 struct se3
35 {
36 public:
38  using scalar_type = T;
39 
42 
45 
48 
51 
54 
56  [[nodiscard]] constexpr se3 inverse() const noexcept
57  {
58  return {-t * r, conjugate(r)};
59  }
60 
63  [[nodiscard]] constexpr matrix_type matrix() const noexcept
64  {
66 
67  m[3].x() = t.x();
68  m[3].y() = t.y();
69  m[3].z() = t.z();
70 
71  return m;
72  }
73 
74  [[nodiscard]] inline constexpr explicit operator matrix_type() const noexcept
75  {
76  return matrix();
77  }
79 
88  [[nodiscard]] inline constexpr vector_type transform(const vector_type& v) const noexcept
89  {
90  return r * v + t;
91  }
92 
93  [[nodiscard]] inline constexpr vector_type operator*(const vector_type& v) const noexcept
94  {
95  return transform(v);
96  }
98 
107  [[nodiscard]] constexpr se3 transform(const se3& xf) const noexcept
108  {
109  return {xf.transform(t), normalize(xf.r * r)};
110  }
111 
112  [[nodiscard]] inline constexpr se3 operator*(const se3& xf) const noexcept
113  {
114  return transform(xf);
115  }
117 
118  /*
119  * Type-casts the transform scalars using `static_cast`.
120  *
121  * @tparam U Target scalar type.
122  *
123  * @return Type-casted transform.
124  */
125  template <class U>
126  [[nodiscard]] inline constexpr explicit operator se3<U>() const noexcept
127  {
128  return {vec3<U>(t), quat<U>(r)};
129  }
130 
132  [[nodiscard]] static inline constexpr se3 identity() noexcept
133  {
135  }
136 };
137 
138 } // namespace math
139 
140 #endif // ANTKEEPER_MATH_TRANSFORMATION_SE3_HPP
Mathematical functions and data types.
Definition: angles.hpp:26
quaternion< T > normalize(const quaternion< T > &q)
Normalizes a quaternion.
Definition: quaternion.hpp:679
constexpr quaternion< T > conjugate(const quaternion< T > &q) noexcept
Calculates the conjugate of a quaternion.
Definition: quaternion.hpp:566
n by m column-major matrix.
Definition: math/matrix.hpp:44
Quaternion composed of a real scalar part and imaginary vector part.
Definition: quaternion.hpp:39
static constexpr quaternion identity() noexcept
Returns a rotation identity quaternion.
Definition: quaternion.hpp:200
SE(3) proper rigid transformation (rototranslation).
Definition: se3.hpp:35
constexpr vector_type transform(const vector_type &v) const noexcept
Transforms a vector by this transformation.
Definition: se3.hpp:88
mat4< T > matrix_type
Transformation matrix type.
Definition: se3.hpp:47
constexpr se3 operator*(const se3 &xf) const noexcept
Transforms an SE(3) transformation by this transformation.
Definition: se3.hpp:112
constexpr se3 inverse() const noexcept
Returns the inverse of this transformation.
Definition: se3.hpp:56
constexpr matrix_type matrix() const noexcept
Returns a matrix representation of this transformation.
Definition: se3.hpp:63
constexpr vector_type operator*(const vector_type &v) const noexcept
Transforms a vector by this transformation.
Definition: se3.hpp:93
static constexpr se3 identity() noexcept
Returns an identity transformation.
Definition: se3.hpp:132
quaternion_type r
Quaternion representing the rotation component of the transformation.
Definition: se3.hpp:53
T scalar_type
Scalar type.
Definition: se3.hpp:38
constexpr se3 transform(const se3 &xf) const noexcept
Transforms an SE(3) transformation by this transformation.
Definition: se3.hpp:107
vector_type t
Vector representing the translation component of the transformation.
Definition: se3.hpp:50
n-dimensional vector.
Definition: vector.hpp:44
constexpr element_type & x() noexcept
Returns a reference to the first element.
Definition: vector.hpp:164
constexpr element_type & y() noexcept
Returns a reference to the second element.
Definition: vector.hpp:180
static constexpr vector zero() noexcept
Returns a zero vector, where every element is equal to zero.
Definition: vector.hpp:306
constexpr element_type & z() noexcept
Returns a reference to the third element.
Definition: vector.hpp:196