yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #04570
Re: [Question #160858]: Geometrical intersection between 2 objects
Question #160858 on Yade changed:
https://answers.launchpad.net/yade/+question/160858
Status: Open => Answered
Chareyre proposed the following answer:
There is no function that you can use straight away, but the code in
Cylinder.cpp lines 56 to 81 is doing exactly that.
I tried to see how it could be isolated in a single function, it looks
like this (below). The only problem is this function can't be wrapped
with python yet (I think) because the arguments are shared pointers.
You'd need to replace the arguments with id1/id2, then define the
cm1/cm2/state1/state2 in the function's body. Finally, you declare the
function in the hpp with ".def()" to use it with python. It should work.
Bruno
bool Ig2_Sphere_ChainedCylinder_CylScGeom::checkOverlap(const
shared_ptr<Shape>& cm1,
const shared_ptr<Shape>& cm2,
const State& state1, const State& state2)
{
const State* sphereSt=YADE_CAST<const State*>(&state1);
const ChainedState* cylinderSt=YADE_CAST<const ChainedState*>(&state2);
ChainedCylinder *cylinder=YADE_CAST<ChainedCylinder*>(cm2.get());
Sphere *sphere=YADE_CAST<Sphere*>(cm1.get());
assert(sphereSt && cylinderSt && cylinder && sphere);
bool isLast =
(cylinderSt->chains[cylinderSt->chainNumber].size()==(cylinderSt->rank+1));
shared_ptr<const ChainedState> statePrev;
if (cylinderSt->rank>0)
statePrev = YADE_PTR_CAST<const ChainedState>
(Body::byId(cylinderSt->chains[cylinderSt->chainNumber][cylinderSt->rank-1],scene)->state);
//FIXME : definition of segment in next line breaks periodicity
shared_ptr<Body> cylinderNext;
Vector3r segment, branch, direction;
Real length, dist;
branch = sphereSt->pos-cylinderSt->pos-shift2;
if (!isLast) {
cylinderNext =
Body::byId(cylinderSt->chains[cylinderSt->chainNumber][cylinderSt->rank+1],scene);
segment = cylinderNext->state->pos-cylinderSt->pos;
if (segment.dot(branch)>(segment.dot(segment)) return false;
length = segment.norm();
direction = segment/length;
dist = direction.dot(branch);
if (dist<-interactionDetectionFactor*cylinder->radius &&
branch.squaredNorm() >
pow(interactionDetectionFactor*(sphere->radius+cylinder->radius),2))
return false;
} else {//handle the last node with length=0
segment = Vector3r(0,0,0);
length = 0;
direction = Vector3r(0,1,0);
dist = 0;
if (branch.squaredNorm() >
interactionDetectionFactor*(sphere->radius+cylinder->radius)) return false;
}
//Check sphere-cylinder distance
Vector3r projectedP = cylinderSt->pos+shift2 + direction*dist;
branch = projectedP-sphereSt->pos;
if (branch.squaredNorm()>(pow(sphere->radius+cylinder->radius,2)))
return false;
return true;
}
--
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.