Skip to content

Commit 9f6e0ee

Browse files
committed
Document ClosestPointQueries
1 parent ed08fbe commit 9f6e0ee

File tree

1 file changed

+70
-51
lines changed

1 file changed

+70
-51
lines changed

source/pbat/geometry/ClosestPointQueries.h

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
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
212
#define PBAT_GEOMETRY_CLOSESTPOINTQUERIES_H
313

414
#include "pbat/HostDevice.h"
@@ -9,103 +19,109 @@
919

1020
namespace pbat {
1121
namespace geometry {
22+
/**
23+
* @brief This namespace contains functions to answer closest point queries.
24+
*/
1225
namespace ClosestPointQueries {
1326

1427
namespace mini = math::linalg::mini;
1528

1629
/**
1730
* @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
2235
*/
2336
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>;
2639

2740
/**
2841
* @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
3346
*/
3447
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>;
3750

3851
/**
3952
* @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
4558
*/
4659
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>;
4963

5064
/**
5165
* @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
5771
*/
5872
template <
5973
mini::CMatrix TMatrixP,
6074
mini::CMatrix TMatrixA,
6175
mini::CMatrix TMatrixB,
6276
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>;
6580

6681
/**
6782
* @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
7388
*/
7489
template <
7590
mini::CMatrix TMatrixP,
7691
mini::CMatrix TMatrixA,
7792
mini::CMatrix TMatrixB,
7893
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>;
8197

8298
/**
8399
* @brief Obtain the point in the tetrahedron ABCD closest to the point P. The order of ABCD
84100
* must be such that all faces ABC, ACD, ADB and BDC are oriented with outwards pointing normals
85101
* 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
92108
*/
93109
template <
94110
mini::CMatrix TMatrixP,
95111
mini::CMatrix TMatrixA,
96112
mini::CMatrix TMatrixB,
97113
mini::CMatrix TMatrixC,
98114
mini::CMatrix TMatrixD>
99-
PBAT_HOST_DEVICE mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows> PointInTetrahedron(
115+
PBAT_HOST_DEVICE auto PointInTetrahedron(
100116
TMatrixP const& P,
101117
TMatrixA const& A,
102118
TMatrixB const& B,
103119
TMatrixC const& C,
104-
TMatrixD const& D);
120+
TMatrixD const& D) -> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows>;
105121

106122
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>
109125
{
110126
using namespace std;
111127
using ScalarType = typename TMatrixX::ScalarType;
@@ -122,8 +138,8 @@ PointOnPlane(TMatrixX const& X, TMatrixP const& P, TMatrixN const& n)
122138
}
123139

124140
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>
127143
{
128144
using ScalarType = typename TMatrixX::ScalarType;
129145
using namespace std;
@@ -141,8 +157,9 @@ PointOnLineSegment(TMatrixX const& X, TMatrixP const& P, TMatrixQ const& Q)
141157
}
142158

143159
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
145161
PointOnAxisAlignedBoundingBox(TMatrixX const& P, TMatrixL const& L, TMatrixU const& U)
162+
-> mini::SVector<typename TMatrixX::ScalarType, TMatrixX::kRows>
146163
{
147164
using namespace std;
148165
/**
@@ -159,8 +176,9 @@ template <
159176
mini::CMatrix TMatrixA,
160177
mini::CMatrix TMatrixB,
161178
mini::CMatrix TMatrixC>
162-
PBAT_HOST_DEVICE mini::SVector<typename TMatrixP::ScalarType, 3>
179+
PBAT_HOST_DEVICE auto
163180
UvwPointInTriangle(TMatrixP const& P, TMatrixA const& A, TMatrixB const& B, TMatrixC const& C)
181+
-> mini::SVector<typename TMatrixP::ScalarType, 3>
164182
{
165183
using ScalarType = typename TMatrixP::ScalarType;
166184
/**
@@ -243,8 +261,9 @@ template <
243261
mini::CMatrix TMatrixA,
244262
mini::CMatrix TMatrixB,
245263
mini::CMatrix TMatrixC>
246-
PBAT_HOST_DEVICE mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows>
264+
PBAT_HOST_DEVICE auto
247265
PointInTriangle(TMatrixP const& P, TMatrixA const& A, TMatrixB const& B, TMatrixC const& C)
266+
-> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows>
248267
{
249268
auto uvw = UvwPointInTriangle(P, A, B, C);
250269
return A * uvw(0) + B * uvw(1) + C * uvw(2);
@@ -256,12 +275,12 @@ template <
256275
mini::CMatrix TMatrixB,
257276
mini::CMatrix TMatrixC,
258277
mini::CMatrix TMatrixD>
259-
PBAT_HOST_DEVICE mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows> PointInTetrahedron(
278+
PBAT_HOST_DEVICE auto PointInTetrahedron(
260279
TMatrixP const& P,
261280
TMatrixA const& A,
262281
TMatrixB const& B,
263282
TMatrixC const& C,
264-
TMatrixD const& D)
283+
TMatrixD const& D) -> mini::SVector<typename TMatrixP::ScalarType, TMatrixP::kRows>
265284
{
266285
using ScalarType = typename TMatrixP::ScalarType;
267286
auto constexpr kRows = TMatrixP::kRows;

0 commit comments

Comments
 (0)