yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #04586
Re: [Question #160858]: Geometrical intersection between 2 objects
Question #160858 on Yade changed:
https://answers.launchpad.net/yade/+question/160858
Status: Answered => Solved
Kneib François confirmed that the question is solved:
OK thanks, I understood but finally I made that in python using the scalar product.
If someone is interested, here is the code :
# encoding: utf-8
from pylab import *
[...]
#Returns the distance between a point and a line in space.
def distPointToLine(A,B,u): #A:the point, #B:a point on the line, #u:vector of the line
BA=[A[0]-B[0],A[1]-B[1],A[2]-B[2]]
return norm(cross(BA,u))/norm(u)
#Returns true if the sphere's projection on the cylinder is in the cylinder's segment. Else return false.
def isProjectionInsideSegment(u,v,rs,rc):#
ratio=inner(u,v)/(norm(u)**2)
rs=rs/norm(u)
rc=rc/norm(u)
if (-rs-rc<ratio<1.0+rs+rc):return True
else: return False
#Erases all the sphere who are penetrated in any cylinder.
def eraseIntersectedSpheres():
for i in O.bodies:
if(type(i.shape).__name__ == 'ChainedCylinder'):
for j in O.bodies:
if(type(j.shape).__name__ == 'Sphere'):
sphereCenter=[j.state.pos[0],j.state.pos[1],j.state.pos[2]]
sphereRadius=j.shape.radius
cylinderRadius=i.shape.radius
cylinderStart=[i.state.pos[0],i.state.pos[1],i.state.pos[2]]
cylinderSegment=[i.shape.segment[0],i.shape.segment[1],i.shape.segment[2]]
cylinderSphereSegment=[sphereCenter[0]-cylinderStart[0],sphereCenter[1]-cylinderStart[1],sphereCenter[2]-cylinderStart[2]]
if (distPointToLine(sphereCenter,cylinderStart,cylinderSegment)<(sphereRadius+cylinderRadius) and isProjectionInsideSegment(cylinderSegment,cylinderSphereSegment,sphereRadius,cylinderRadius)):
O.bodies.erase(j.id)
[...]
--
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.