-
Notifications
You must be signed in to change notification settings - Fork 417
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
Change shape-shape intersection API to return multiple contacts #52
Change shape-shape intersection API to return multiple contacts #52
Conversation
A small comment: in the old API, you could ask for just the contact normals, or just the contact points, or just the distances. Now all of them are copied, whether you need all of them or just one of them. This makes the API a lot cleaner, though. It shouldn't affect users who only need to know whether there is a collision. |
I considered to make them can be asked separately in the first place but didn't. The reason was that it seemed there are only two cases: they are all null pointers or not null pointers. For example, GJKCollide assumes all of them are not null pointers if contact point is not null pointer. If FCL still want to make them separate parameters then I'm fine with that. Even though they all go together, it still doesn't affect users who only need to know whether there is a collision. In that case, the user should pass null pointer at the place of contact list parameter as: bool res = gjk_solver.shapeIntersect(shape1, tf1, shape2, tf2, NULL); |
Yes, I understand. I'll leave it to someone else to give more detailed feedback and accept/reject the PR, but this looks fine to me. |
Thanks! I welcome any feedback or questions. |
- Fix use of std::partial_sort - Add safety check in case that the total contact result was initially non-empty
…sion_api Conflicts: include/fcl/narrowphase/narrowphase.h src/narrowphase/narrowphase.cpp
template<typename S1, typename S2> | ||
bool shapeIntersect(const S1& s1, const Transform3f& tf1, | ||
const S2& s2, const Transform3f& tf2, | ||
std::vector<ContactPoint>* contacts) const |
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.
Is it better to pass Never mind, it looks like you make it a pointer so that it can be treated as an optional output.contacts
as a pointer or pass by reference?
Does it make sense to assign a default value of contacts=NULL
?
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.
It makes sense to me. I can see there are other functions we can pass default function parameters such as shapeTriangleIntersect
, shapeDistance
, and shapeTriangleDistance
.
Especially, shapeDistance(const S1&, const Transform3f&, const S2&, const Transform3f&, FCL_REAL*)
looks redundant once we have shapeDistance(const S1&, const Transform3f&, const S2&, const Transform3f&, FCL_REAL* = NULL, Vec3f* = NULL, Vec3f* = NULL)
.
…turn true if the first element is less than the second.
Looks like there's conflicts again |
Right, the most conflicts are in |
…on_api Resolved conflicts: include/fcl/narrowphase/narrowphase.h src/narrowphase/narrowphase.cpp test/test_fcl_geometric_shapes.cpp
…-sphere test is applied
In the recent commits, I improved shape-shape collision test suits for multiple contacts and updated all the tests in |
Excellent work JS, this is a great start on improve FCL versatility. +1 |
Thanks John, I will wait another day for further feedback before merge this PR. |
Change shape-shape intersection API to return multiple contacts
This pull request enables FCL to return multiple contacts per primitive-primitive collision. This feature is essential when FCL is used in physics simulation. For example, if we want to stack a primitive shape on another primitive shape in presence of gravity, multiple contacts are required to support the upper object. Single contact will make it unstable.
As I known, the most low level collision object types in FCL are triangle and primitive shapes. Depending on the kind of primitive shape, FCL uses different collision algorithms. Here is the category of collision algorithms in FCL:
All the collision algorithms returns single contact point. If a mesh and other collision object are colliding, multiple contacts can be detected because a mesh consists of many of triangles. The problem is the case that two primitive shapes are colliding. Although the algorithm for specific primitive shapes combination (e.g, box-box), it had to pick a single contact or average them because of the limitation of API. So I propose to change the API to be able to return multiple contacts as:
As of now, box-box collision algorithm is the only one can detect multiple contacts. Other collision algorithm for different combination of primitive shapes needs to be implemented. This will be done in following pull requests.
Since the previous API, which is exposed to the user, is just marked as deprecated instead of removed, this PR doesn't hurt the backward compatibility. With this new API, all the unit tests (those were not broken as itself) are passing.
This pull request also fixes #15.