Is there a collision detection method for meshes? #38
-
Hi, i want to difference multiple machining features from a cube randomly. For example, i want to difference a 10mm and 5mm drill hole from the cube. If i substract first the 10mm drill hole and then the 5mm at the same place, there will be an exception because there is no mesh i can difference the 5mm from. So, i would like to randomly place the 10mm and 5mm drillholes first and check if both colide. If so, i unite both with the boolean operation and then difference them from the cube. Therefore, i need a method to check, if both drillholes are colliding after randomly placing them. Is there such a function? Kind Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hello @Boehm92 ! About drillingI'm not sure to understand the need of an intersection-check function in this case, as there is nothing wrong in performing a boolean union or difference when the meshes are not intersecting. In case of non intersecting meshes, a union will simply concatenate them, resulting in one mesh containing 2 islands, a difference will result in only the first mesh unmodified. from madcad import *
def cylinder(bottom:vec3, top:vec3, radius:float) -> 'Mesh':
direction = top-bottom
return extrusion(direction,
flatsurface(wire(Circle((bottom,normalize(direction)), radius)))
.flip())
cube = brick(width=vec3(1))
c1 = cylinder(O, Z, 0.2)
c2 = cylinder(vec3(1,0,0.1), vec3(1,0,0.9), 0.2)
c3 = cylinder(vec3(0.2,0,0.2), vec3(0.2,0,0.8), 0.15)
# both following solutions are valid:
result = difference(difference(difference(cube, c1), c2), c3) # performing drill holes one by one
result = difference(cube, union(union(c1, c2), c3)) # making a union of the drills and then performing the holes all at once About intersection-checkFor the question of intersection-check itself, I might have a solution, but not very efficient ... The lowest level intersection function available in the API is However it is meant to actually compute intersections, so it will compute all the intersections before returning, instead of stopping at the first existing intersection found, as a good intersection-check would do. If you really need to check for intersections (or possible intersections) between meshes, I would advice creating dedicated functions, using for instance the following techniques:
If you really need such a function I think I could hack something 🤔 |
Beta Was this translation helpful? Give feedback.
Hello @Boehm92 !
About drilling
I'm not sure to understand the need of an intersection-check function in this case, as there is nothing wrong in performing a boolean union or difference when the meshes are not intersecting. In case of non intersecting meshes, a union will simply concatenate them, resulting in one mesh containing 2 islands, a difference will result in only the first mesh unmodified.
Here is an example of what I understand of your case: