1
- #ifndef PBAT_GEOMETRY_CLOSESTPOINTQUERIES_H
1
+ /* *
2
+ * @file ClosestPointQueries.h
3
+ * @author Quoc-Minh Ton-That ([email protected] )
4
+ * @brief This file contains functions to answer closest point queries.
5
+ * @date 2025-02-12
6
+ *
7
+ * @copyright Copyright (c) 2025
8
+ *
9
+ */
10
+
11
+ #ifndef PBAT_GEOMETRY_CLOSESTPOINTQUERIES_H
2
12
#define PBAT_GEOMETRY_CLOSESTPOINTQUERIES_H
3
13
4
14
#include " pbat/HostDevice.h"
9
19
10
20
namespace pbat {
11
21
namespace geometry {
22
+ /* *
23
+ * @brief This namespace contains functions to answer closest point queries.
24
+ */
12
25
namespace ClosestPointQueries {
13
26
14
27
namespace mini = math::linalg::mini;
15
28
16
29
/* *
17
30
* @brief Obtain the point on the plane (P,n) closest to the point X.
18
- * @param X
19
- * @param P
20
- * @param n
21
- * @return
31
+ * @param X Query point
32
+ * @param P Point on the plane
33
+ * @param n Normal of the plane
34
+ * @return Point on the plane closest to X
22
35
*/
23
36
template <mini::CMatrix TMatrixX, mini::CMatrix TMatrixP, mini::CMatrix TMatrixN>
24
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixX::ScalarType, TMatrixX:: kRows >
25
- PointOnPlane (TMatrixX const & X, TMatrixP const & P, TMatrixN const & n) ;
37
+ PBAT_HOST_DEVICE auto PointOnPlane ( TMatrixX const & X, TMatrixP const & P, TMatrixN const & n)
38
+ -> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows> ;
26
39
27
40
/* *
28
41
* @brief Obtain the point on the line segment PQ closest to the point X.
29
- * @param X
30
- * @param P
31
- * @param Q
32
- * @return
42
+ * @param X Query point
43
+ * @param P Start point of the line segment
44
+ * @param Q End point of the line segment
45
+ * @return Point on the line segment closest to X
33
46
*/
34
47
template <mini::CMatrix TMatrixX, mini::CMatrix TMatrixP, mini::CMatrix TMatrixQ>
35
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixX::ScalarType, TMatrixX:: kRows >
36
- PointOnLineSegment (TMatrixX const & X, TMatrixP const & P, TMatrixQ const & Q) ;
48
+ PBAT_HOST_DEVICE auto PointOnLineSegment ( TMatrixX const & X, TMatrixP const & P, TMatrixQ const & Q)
49
+ -> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows> ;
37
50
38
51
/* *
39
52
* @brief Obtain the point on the axis-aligned bounding box (AABB) defined by the lower
40
- * and upper corners closest to the point P .
41
- * @param P
42
- * @param L
43
- * @param U
44
- * @return
53
+ * and upper corners closest to the point X .
54
+ * @param X Query point
55
+ * @param L Lower corner of the AABB
56
+ * @param U Upper corner of the AABB
57
+ * @return Point on the AABB closest to X
45
58
*/
46
59
template <mini::CMatrix TMatrixX, mini::CMatrix TMatrixL, mini::CMatrix TMatrixU>
47
- PBAT_HOST_DEVICE mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows >
48
- PointOnAxisAlignedBoundingBox (TMatrixX const & X, TMatrixL const & L, TMatrixU const & U);
60
+ PBAT_HOST_DEVICE auto
61
+ PointOnAxisAlignedBoundingBox (TMatrixX const & X, TMatrixL const & L, TMatrixU const & U)
62
+ -> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows >;
49
63
50
64
/* *
51
65
* @brief Obtain the point on the triangle ABC closest to the point P in barycentric coordinates.
52
- * @param P
53
- * @param A
54
- * @param B
55
- * @param C
56
- * @return
66
+ * @param P Query point
67
+ * @param A Vertex A of the triangle
68
+ * @param B Vertex B of the triangle
69
+ * @param C Vertex C of the triangle
70
+ * @return Barycentric coordinates of the point in the triangle closest to P
57
71
*/
58
72
template <
59
73
mini::CMatrix TMatrixP,
60
74
mini::CMatrix TMatrixA,
61
75
mini::CMatrix TMatrixB,
62
76
mini::CMatrix TMatrixC>
63
- PBAT_HOST_DEVICE mini::SVector<typename TMatrixP::ScalarType, 3 >
64
- UvwPointInTriangle (TMatrixP const & P, TMatrixA const & A, TMatrixB const & B, TMatrixC const & C);
77
+ PBAT_HOST_DEVICE auto
78
+ UvwPointInTriangle (TMatrixP const & P, TMatrixA const & A, TMatrixB const & B, TMatrixC const & C)
79
+ -> mini::SVector<typename TMatrixP::ScalarType, 3 >;
65
80
66
81
/* *
67
82
* @brief Obtain the point on the triangle ABC closest to the point P.
68
- * @param P
69
- * @param A
70
- * @param B
71
- * @param C
72
- * @return
83
+ * @param P Query point
84
+ * @param A Vertex A of the triangle
85
+ * @param B Vertex B of the triangle
86
+ * @param C Vertex C of the triangle
87
+ * @return Point in the triangle closest to P
73
88
*/
74
89
template <
75
90
mini::CMatrix TMatrixP,
76
91
mini::CMatrix TMatrixA,
77
92
mini::CMatrix TMatrixB,
78
93
mini::CMatrix TMatrixC>
79
- PBAT_HOST_DEVICE mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows >
80
- PointInTriangle (TMatrixP const & P, TMatrixA const & A, TMatrixB const & B, TMatrixC const & C);
94
+ PBAT_HOST_DEVICE auto
95
+ PointInTriangle (TMatrixP const & P, TMatrixA const & A, TMatrixB const & B, TMatrixC const & C)
96
+ -> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows >;
81
97
82
98
/* *
83
99
* @brief Obtain the point in the tetrahedron ABCD closest to the point P. The order of ABCD
84
100
* must be such that all faces ABC, ACD, ADB and BDC are oriented with outwards pointing normals
85
101
* when viewed from outside the tetrahedron.
86
- * @param P
87
- * @param A
88
- * @param B
89
- * @param C
90
- * @param D
91
- * @return
102
+ * @param P Query point
103
+ * @param A Vertex A of the tetrahedron
104
+ * @param B Vertex B of the tetrahedron
105
+ * @param C Vertex C of the tetrahedron
106
+ * @param D Vertex D of the tetrahedron
107
+ * @return Point in the tetrahedron closest to P
92
108
*/
93
109
template <
94
110
mini::CMatrix TMatrixP,
95
111
mini::CMatrix TMatrixA,
96
112
mini::CMatrix TMatrixB,
97
113
mini::CMatrix TMatrixC,
98
114
mini::CMatrix TMatrixD>
99
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixP::ScalarType, TMatrixP:: kRows > PointInTetrahedron (
115
+ PBAT_HOST_DEVICE auto PointInTetrahedron (
100
116
TMatrixP const & P,
101
117
TMatrixA const & A,
102
118
TMatrixB const & B,
103
119
TMatrixC const & C,
104
- TMatrixD const & D);
120
+ TMatrixD const & D) -> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows> ;
105
121
106
122
template <mini::CMatrix TMatrixX, mini::CMatrix TMatrixP, mini::CMatrix TMatrixN>
107
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixX::ScalarType, TMatrixX:: kRows >
108
- PointOnPlane (TMatrixX const & X, TMatrixP const & P, TMatrixN const & n)
123
+ PBAT_HOST_DEVICE auto PointOnPlane ( TMatrixX const & X, TMatrixP const & P, TMatrixN const & n)
124
+ -> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows>
109
125
{
110
126
using namespace std ;
111
127
using ScalarType = typename TMatrixX::ScalarType;
@@ -122,8 +138,8 @@ PointOnPlane(TMatrixX const& X, TMatrixP const& P, TMatrixN const& n)
122
138
}
123
139
124
140
template <mini::CMatrix TMatrixX, mini::CMatrix TMatrixP, mini::CMatrix TMatrixQ>
125
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixX::ScalarType, TMatrixX:: kRows >
126
- PointOnLineSegment (TMatrixX const & X, TMatrixP const & P, TMatrixQ const & Q)
141
+ PBAT_HOST_DEVICE auto PointOnLineSegment ( TMatrixX const & X, TMatrixP const & P, TMatrixQ const & Q)
142
+ -> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows>
127
143
{
128
144
using ScalarType = typename TMatrixX::ScalarType;
129
145
using namespace std ;
@@ -141,8 +157,9 @@ PointOnLineSegment(TMatrixX const& X, TMatrixP const& P, TMatrixQ const& Q)
141
157
}
142
158
143
159
template <mini::CMatrix TMatrixX, mini::CMatrix TMatrixL, mini::CMatrix TMatrixU>
144
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixX::ScalarType, TMatrixX:: kRows >
160
+ PBAT_HOST_DEVICE auto
145
161
PointOnAxisAlignedBoundingBox (TMatrixX const & P, TMatrixL const & L, TMatrixU const & U)
162
+ -> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows >
146
163
{
147
164
using namespace std ;
148
165
/* *
@@ -159,8 +176,9 @@ template <
159
176
mini::CMatrix TMatrixA,
160
177
mini::CMatrix TMatrixB,
161
178
mini::CMatrix TMatrixC>
162
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixP::ScalarType, 3 >
179
+ PBAT_HOST_DEVICE auto
163
180
UvwPointInTriangle (TMatrixP const & P, TMatrixA const & A, TMatrixB const & B, TMatrixC const & C)
181
+ -> mini::SVector<typename TMatrixP::ScalarType, 3 >
164
182
{
165
183
using ScalarType = typename TMatrixP::ScalarType;
166
184
/* *
@@ -243,8 +261,9 @@ template <
243
261
mini::CMatrix TMatrixA,
244
262
mini::CMatrix TMatrixB,
245
263
mini::CMatrix TMatrixC>
246
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixP::ScalarType, TMatrixP:: kRows >
264
+ PBAT_HOST_DEVICE auto
247
265
PointInTriangle (TMatrixP const & P, TMatrixA const & A, TMatrixB const & B, TMatrixC const & C)
266
+ -> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows >
248
267
{
249
268
auto uvw = UvwPointInTriangle (P, A, B, C);
250
269
return A * uvw (0 ) + B * uvw (1 ) + C * uvw (2 );
@@ -256,12 +275,12 @@ template <
256
275
mini::CMatrix TMatrixB,
257
276
mini::CMatrix TMatrixC,
258
277
mini::CMatrix TMatrixD>
259
- PBAT_HOST_DEVICE mini::SVector< typename TMatrixP::ScalarType, TMatrixP:: kRows > PointInTetrahedron (
278
+ PBAT_HOST_DEVICE auto PointInTetrahedron (
260
279
TMatrixP const & P,
261
280
TMatrixA const & A,
262
281
TMatrixB const & B,
263
282
TMatrixC const & C,
264
- TMatrixD const & D)
283
+ TMatrixD const & D) -> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows>
265
284
{
266
285
using ScalarType = typename TMatrixP::ScalarType;
267
286
auto constexpr kRows = TMatrixP::kRows ;
0 commit comments