-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return the correct nearest points from distance(...)
#215
Return the correct nearest points from distance(...)
#215
Conversation
This allows the user to control the tolerance used in the GJK solvers without explicitly constructing a solver.
@jslee02, do you have any insights as to why libccd would return different results on Linux than it does on Windows and OSX? |
One possible reason would be that |
Hmmm. I've been using the |
I realized that If this is the cause of the issue, then we might want to add a precision option to the homebrew formula. |
Is FCL really useful in single precision? Likely it could at least default to double everywhere, but it might be worth simply declaring that only double is supported, especially if there are unit tests that won't pass in float. |
I think Jeongseok was talking about the default build option for libccd,
not FCL.
…--------------------------------
Evan Drumwright
Senior Research Scientist
http://positronicslab.github.io
Toyota Research Institute
Palo Alto, CA
On Thu, Jun 1, 2017 at 8:19 AM, Michael Sherman ***@***.***> wrote:
Is FCL really useful in single precision? Likely it could at least default
to double everywhere, but it might be worth simply declaring that only
double is supported, especially if there are unit tests that won't pass in
float.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#215 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACHwz8VN2WcmsXZM7it6hz2Nff15SDDFks5r_taegaJpZM4NsJL->
.
|
@jslee02, it looks like that's the issue. I verified that |
Thanks for finding the precision issue, @jslee02! I think we should update the homebrew formula to use double precision. @jslee02 do you have experience editing homebrew formulae? If so, could you put in a pull request with that change? I haven't the slightest idea how to go about testing changes to homebrew configuration. I'm willing to learn, but if you already have that know-how, it would be awesome if you could put that in 😃 Additionally, is there a way to require at build time that libccd was built with double precision (i.e. that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of notes. Doesn't address correctness, per se, but attempts to strengthen the code that's there.
// p - A = s*AB | ||
// | ||
// This defines three equations, but we only need one. Take the x | ||
// component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quality of this solution degrades as the line segment becomes more perpendicular to the x-axis (i.e., where B_x - A_x << 1
. Ideally, you'd want to pick the axis where |B_i - A_i|
is biggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
// | ||
// Thus, s is given by | ||
// | ||
// s = (p_x - A_x)/(B_x - vA_x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo? vA_x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// t = n . (AB x p') / n . (AB x AC) | ||
double s{-ccdVec3Dot(&n, &AC_cross_v_prime) / n_dot_AB_cross_AC}; | ||
double t{ccdVec3Dot(&n, &AB_cross_v_prime) / n_dot_AB_cross_AC}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a little algebraic manipulation simplifies the math (making it cheaper and more robust -- no square roots and fewer floating point ops).
Starting with the following definitions (and focusing only on t
with the understanding that it applies directly to s
:
n = AB x AC
n̂ = n / ||n||
t = n̂⋅(AC x p') / (n̂⋅(AB x AC))
We get the following:
t = n̂⋅(AC x p') / (n̂⋅(AB x AC)) - the given equation
t = (n / ||n||)⋅(AC x p') / ((n / ||n||)⋅(AB x AC)) - substitute for n̂
t = n⋅(AC x p') / (n⋅(AB x AC)) - cancel 1 / ||n||
t = (AB x AC)⋅(AC x p') / ((AB x AC)⋅(AB x AC)) - substitute for n
t = (AB x AC)⋅(AC x p') / ||AB x AC||² - simplify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Done. PTAL.
double A_x{ccdVec3X(&(simplex->ps[0].v))}; | ||
double B_x{ccdVec3X(&(simplex->ps[1].v))}; | ||
double p_x{ccdVec3X(p)}; | ||
double s{(p_x - A_x) / (B_x - A_x)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra space proceeding s
I think I could do that. Let me put that it to my list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Submitted a PR: Homebrew/homebrew-science#5762 |
5638747
to
ee065f8
Compare
I see that the homebrew PR went through! Is there a way to re-trigger the CI checks for this PR? |
Sorry for delayed response. #216 is now merged. Could you merge master into this PR so that the CI checks are re-triggered as well? |
It looks good to me. Adding a new parameter to |
Is it possible that the cached libccd is still single precision on the x64 Windows machine? |
I believe so. Let's refresh the cache by removing it and adding it back (enabling the cache). |
This reverts commit 81b20e3.
OK, the appveyor/pr check passed once the cache was cleared. I've re-enabled the cache now. |
Now the libccd cache should be invalidated whenever `.appveyor.yml` is modified.
@jslee02: appveyor/pr is finally happy! What's being checked in appveyor/branch? |
I believe appveyor/branch checks for regular commits to the branch, but it seems not to work sometimes. I just removed it from the requirements as suggested in the post. Merging this! Thank you for the contribution! |
This PR fixes issues in both the CCD-based and the independent GJK solvers, which caused
distance
to return erroneous values for the nearest points.simplex
variable. The points on the original shapes can be computed from thesimplex
and the nearest point to the origin on the Minkowski difference,dir
.p2
is not properly transformed to its shape's (shape1
) frame.toshape0
converts points fromshape1
frame toshape0
frame. The points extracted from the GJK simplex are inshape0
frame, so the inverse oftoshape0
needs to be applied.The
test_fcl_capsule_box_*
tests contained lines that failed due to the issues described above. This PR uncomments those lines and modifies the tests to exercise both solvers.This PR also adds a
distance_tolerance
member tofcl::DistanceRequest
, which corresponds to thedistance_tolerance
andgjk_tolerance
members inGJKSolver_libccd
andGJKSolver_indep
respectively. @jslee02, is this an appropriate way to expose this knob to the user? I didn't useabs_err
because the default for that was 0.0, whereas the defaults fordistance_tolerance
andgjk_tolerance
are 1e-6.