PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
Geometry.h
1#ifndef PBAT_MATH_LINALG_MINI_GEOMETRY_H
2#define PBAT_MATH_LINALG_MINI_GEOMETRY_H
3
4#include "Api.h"
5#include "Concepts.h"
6#include "pbat/HostDevice.h"
7
8#include <type_traits>
9#include <utility>
10
11namespace pbat {
12namespace math {
13namespace linalg {
14namespace mini {
15
16template <class /*CMatrix*/ TLhsMatrix, class /*CMatrix*/ TRhsMatrix>
17class CrossProduct
18{
19 public:
20 static_assert(
21 ((TLhsMatrix::kRows == 3 and TLhsMatrix::kCols == 1) or
22 (TLhsMatrix::kRows == 1 and TLhsMatrix::kCols == 3)) and
23 ((TRhsMatrix::kRows == 3 and TRhsMatrix::kCols == 1) or
24 (TRhsMatrix::kRows == 1 and TRhsMatrix::kCols == 3)),
25 "Cross product only valid for 3x1 or 1x3 matrices");
26
27 using LhsNestedType = TLhsMatrix;
28 using RhsNestedType = TRhsMatrix;
29
30 using ScalarType = LhsNestedType::ScalarType;
31 using SelfType = CrossProduct<LhsNestedType, RhsNestedType>;
32
33 static auto constexpr kRows = 3;
34 static auto constexpr kCols = 1;
35 static bool constexpr bRowMajor = false;
36
37 PBAT_HOST_DEVICE CrossProduct(LhsNestedType const& _A, RhsNestedType const& _B) : A(_A), B(_B)
38 {
39 }
40
41 PBAT_HOST_DEVICE ScalarType operator()(auto i, auto j) const
42 {
43 j = (i + 1) % 3;
44 i = (i + 2) % 3;
45 return A(j, 0) * B(i, 0) - A(i, 0) * B(j, 0);
46 }
47
48 // Vector(ized) access
49 PBAT_HOST_DEVICE ScalarType operator()(auto i) const { return (*this)(i, 0); }
50 PBAT_HOST_DEVICE ScalarType operator[](auto i) const { return (*this)(i); }
51
52 PBAT_MINI_READ_API(SelfType)
53
54 private:
55 LhsNestedType const& A;
56 RhsNestedType const& B;
57};
58
59template <class /*CMatrix*/ TLhsMatrix, class /*CMatrix*/ TRhsMatrix>
60PBAT_HOST_DEVICE auto Cross(TLhsMatrix&& A, TRhsMatrix&& B)
61{
62 using LhsMatrixType = std::remove_cvref_t<TLhsMatrix>;
63 using RhsMatrixType = std::remove_cvref_t<TRhsMatrix>;
65 std::forward<TLhsMatrix>(A),
66 std::forward<TRhsMatrix>(B));
67}
68
69} // namespace mini
70} // namespace linalg
71} // namespace math
72} // namespace pbat
73
74#endif // PBAT_MATH_LINALG_MINI_GEOMETRY_H
Mini linear algebra related functionality.
Definition Assign.h:12
Linear Algebra related functionality.
Definition FilterEigenvalues.h:7
Math related functionality.
Definition Concepts.h:19
The main namespace of the library.
Definition Aliases.h:15