@@ -287,65 +287,11 @@ class TriangleSurfaceMesh {
287
287
(b₀, b₁, b₂) still satisfy b₀ + b₁ + b₂ = 1; however, some bᵢ will be
288
288
negative.
289
289
@pre t ∈ {0, 1, 2,..., num_triangles()-1}.
290
- */
290
+ @tparam C must be either `double` or `AutoDiffXd`. */
291
291
template <typename C>
292
292
Barycentric<promoted_numerical_t <T, C>> CalcBarycentric (
293
- const Vector3<C>& p_MQ, int t) const {
294
- const Vector3<T>& v0 = vertex (element (t).vertex (0 ));
295
- const Vector3<T>& v1 = vertex (element (t).vertex (1 ));
296
- const Vector3<T>& v2 = vertex (element (t).vertex (2 ));
297
- // Translate the triangle to the origin to simplify calculations;
298
- // barycentric coordinates stay the same.
299
- // u⃗i = v⃗i - v0
300
- // p_MR = p_MQ - v0
301
- //
302
- // Consider R' on the spanning plane through the origin, u1, u2:
303
- // R' = b₀*u0 + b₁*u1 + b₂*u2
304
- // = 0 + b₁*u1 + b₂*u2
305
- // = b₁*u1 + b₂*u2
306
- //
307
- // Solve for b₁, b₂ that give R' "closest" to R in the least square sense:
308
- //
309
- // | ||b1|
310
- // |u⃗1 u⃗2||b2| ~ R'
311
- // | |
312
- //
313
- // return Barycentric (1-b₁-b₂, b₁, b₂)
314
- //
315
- using ReturnType = promoted_numerical_t <T, C>;
316
- Eigen::Matrix<ReturnType, 3 , 2 > A;
317
- A.col (0 ) << v1 - v0;
318
- A.col (1 ) << v2 - v0;
319
- Vector2<ReturnType> solution = A.colPivHouseholderQr ().solve (p_MQ - v0);
320
-
321
- const ReturnType& b1 = solution (0 );
322
- const ReturnType& b2 = solution (1 );
323
- const ReturnType b0 = T (1 .) - b1 - b2;
324
- return {b0, b1, b2};
325
- }
326
- // TODO(DamrongGuoy): Investigate alternative calculation suggested by
327
- // Alejandro Castro:
328
- // 1. Starting with the same ui and p_MR.
329
- // 2. Calculate the unit normal vector n to the spanning plane S through
330
- // the origin, u1, and u2.
331
- // n = u1.cross(u2).normalize().
332
- // 3. Project p_MR to p_MR' on the plane S,
333
- // p_MR' = p_MR - (p_MR.dot(n))*n
334
- //
335
- // Now we have p_MR' = b₀*u⃗0 + b₁*u⃗1 + b₂*u⃗2 by barycentric coordinates.
336
- // = 0 + b₁*u1 + b₂*u2
337
- //
338
- // 5. Solve for b₁ and b₂.
339
- // (b₁*u1 + b₂*u2).dot(u1) = p_MR'.dot(u1)
340
- // (b₁*u1 + b₂*u2).dot(u2) = p_MR'.dot(u2)
341
- // Therefore, the 2x2 system:
342
- // |u1.dot(u1) u2.dot(u1)||b1| = |p_MR'.dot(u1)|
343
- // |u1.dot(u2) u2.dot(u2)||b2| |p_MR'.dot(u2)|
344
- //
345
- // 6. return Barycentric(1-b₁-b₂, b₁, b₂)
346
- //
347
- // Optimization: save n, and the inverse of matrix |uᵢ.dot(uⱼ)| for later.
348
- //
293
+ const Vector3<C>& p_MQ, int t) const
294
+ requires scalar_predicate<C>::is_bool;
349
295
350
296
// TODO(DamrongGuoy): Consider using an oriented bounding box in obb.h.
351
297
// Currently we have a problem that TriangleSurfaceMesh and its vertices are
0 commit comments