Skip to content
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

How can i calculate all the contact triangles pairs in hpp::fcl::BVHModel<hpp::fcl::OBBRSS>? #615

Open
damengziuu opened this issue Aug 8, 2024 · 0 comments

Comments

@damengziuu
Copy link

damengziuu commented Aug 8, 2024

I want to use this library to calculate all the triangle pairs that come into contact when two convex bodies come into contact. But now I can only get the boundary of the intersecting convex bodies.
How should I solve this problem? I'll make sure I set more pieces to detect than triangles

Here is my code:
// Initial position
Transform3f tf1; // identity
Transform3f tf2; // identity
Eigen::MatrixXd tR1(3, 3),tR2(3, 3);
Eigen::MatrixXd tT1(3, 1),tT2(3, 1);
tR1 << 1.0000000000000000, 0, 0,
0, 1, 0,
0, 0, 1;
tT1 << 0.25900000099999998,
0.091704199000000000,
0.14302674900000001;
tf1.setRotation(tR1);
tf1.setTranslation(tT1);

tR2 << 1.0000000000000000, 0, 0,
	0, 1, 0,
	0, 0, 1;
tT2 << 0.26099999699999998,
	0.16467816463778484,
	0.18763962100000001;
tf2.setRotation(tR2);
tf2.setTranslation(tT2);

// 读文件 Isurf-ID 和 Jsurf-ID 
std::shared_ptr<std::vector<Triangle>> IsurfTri(new std::vector<Triangle>);
std::shared_ptr<std::vector<Triangle>> JsurfTri(new std::vector<Triangle>);
parseTriIdFile("D:/Demo/TestReadFile/0.02sFile/IsurfTriID.txt",
	IsurfTri);

parseTriIdFile("D:/Demo/TestReadFile/0.02sFile/JsurfTriID.txt",
	JsurfTri);

// read file points position 
std::shared_ptr < std::vector<Vec3f>> Ipos(new std::vector<Vec3f>);
std::shared_ptr < std::vector<Vec3f>> Jpos(new std::vector<Vec3f>);
parseTriPosFile("D:/Demo/TestReadFile/0.02sFile/IsurfTriPointRapid.txt",
	Ipos);
parseTriPosFile("D:/Demo/TestReadFile/0.02sFile/JsurfTriPointRapid.txt",
	Jpos);


CollisionResult col_res;
const ContactPatchRequest patch_req;
ContactPatchResult patch_res(patch_req);
CollisionRequest col_req(CollisionRequestFlag::DISTANCE_LOWER_BOUND, (*Jpos).size());
col_req.distance_upper_bound = 0.1;


hpp::fcl::BVHModel<hpp::fcl::OBBRSS> iSurfMesh;
iSurfMesh.beginModel();
iSurfMesh.addSubModel(*Ipos, *IsurfTri);
iSurfMesh.endModel();

hpp::fcl::BVHModel<hpp::fcl::OBBRSS> jSurfMesh;
jSurfMesh.beginModel();
jSurfMesh.addSubModel(*Jpos, *JsurfTri);
jSurfMesh.endModel();

col_res.clear(); 
patch_res.clear();
hpp::fcl::collide(&iSurfMesh, tf1, &jSurfMesh, tf2, col_req, col_res); 
std::cout << col_res.isCollision() << "\n";
std::cout << col_res.numContacts() << "\n";

// Take surf id
std::vector<int> salveContactId;
std::vector<int> masterContactId;
std::vector<std::pair<size_t, size_t>> contactPairs;
// show the penetration_depth
for (auto singelCol:col_res.getContacts())
{
	salveContactId.emplace_back(singelCol.b2);
	masterContactId.emplace_back(singelCol.b1);
	contactPairs.emplace_back(std::make_pair(singelCol.b1, singelCol.b2));
}

my result:
B~C2J@R0R}U (40PPYFI_`N

@damengziuu damengziuu changed the title How can i calculate all the contact triangles in hpp::fcl::BVHModel<hpp::fcl::OBBRSS>? How can i calculate all the contact triangles pairs in hpp::fcl::BVHModel<hpp::fcl::OBBRSS>? Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant