Replies: 1 comment 14 replies
-
When A and C are swapped MustIncludeC loses its meaning, so you cannot at compile time decide which edges you can skip. The idea behind swapping was that if you don't swap A and C, you will compare 2 nearly parallel line segments, and the calculations d1 .. d4 and consequently the closest point becomes less accurate. So I don't think it is only the normal 'n' that gets affected by the swap. We could start skipping edges that include A in case A and C were swapped, but that leads to a lot of extra ifs and modern CPUs don't like ifs and rather run through a bunch of extra code.
I'm not quite sure I understand your question. What do you think is wrong about the code?
I think you're right here. My bad. I've fixed this in #742 and that should speed things up a little bit. Thanks for that!
Initially, this EPA convex hull algorithm was the only convex hull algorithm I had. This started generating conflicts as the main purpose of the EPA convex hull builder is to be fast (which means for example that it is completely without memory allocations) while building ConvexHullShapes needed to be accurate and e.g. deal with 2D convex hulls as well. So, yes it could probably lead to better results if you use the fully fledged version but it would also cause the whole simulation to run really slowly. |
Beta Was this translation helpful? Give feedback.
-
Recently, I walked myself through your implementation of GJK/EPA, and I would like to take the opportunity to discuss some aspects of it with you.
(1) MustIncludeC/D
I understand the idea of that boolean from [Theorem 4.7, 1]. What I find curious is that you apply that theorem only on the degenerated case. E.g., why not skip the edge AB in GetClosestPointOnTriangle when MustIncludeC is true? Did you find that the performance gain is neglectable?
Moreover, in GetClosestPointOnTriangle you are swapping the vertices A with C under some condition. But then edge BC can also be edge AB and MustIncludeC looses its meaning:
JoltPhysics/Jolt/Geometry/ClosestPoint.h
Lines 238 to 241 in a58e548
If the only scope of swapping A with C is a numerical more stable calculation of the normal n, what do you think of putting the following code at the beginning of GetClosestPointOnTriangle and removing swap_ac and its logic?
(2) OriginOutsideOfTetrahedronPlanes
Lets look at
JoltPhysics/Jolt/Geometry/ClosestPoint.h
Lines 367 to 372 in a58e548
By the scalar triple product and some basic properties of the cross product, we have
signd0 = signd1 = signd2 = signd3.
Thus, only numerical issues can lead to the case that sign_bits is neither all positive or negative, and we can not deduce from sign_bits if the underlying tetrahedron is degenerated (the vertices A, B, C, and D are affinely dependent) or not. (Needless to say, the tetrahedron is degenerated if
abs(signd0) <= eps
for some eps >= 0; ideally, eps = 0). But maybe I am wrong on this. I would be grateful if you can lead me into the right direction on this matter.(3) Unreachable code in CastRay and CastShape
Lets look at
JoltPhysics/Jolt/Geometry/GJKClosestPoint.h
Lines 612 to 625 in a58e548
If set == 0xf (0b1111), then GetClosestPointOnTetrahedron must have returned Vec3::sZero() and v_len_sq should be zero. Hence, it is not possible to reach the line saying
needs_restart = true
, or am I wrong?(4) EPA
In the implementation of EPA you are using a tailored convex hull algorithm. I am curious if you have tried to use your fully fledged convex hull algorithm and if this can lead to better results? E.g., would you use the latter one in EPA when precision is required?
I am looking forward to your feedback. Thank you in advance.
[1] Collision Detection in Interactive 3D Environments by Gino Van den Bergen
Beta Was this translation helpful? Give feedback.
All reactions