CadQuery / CadQuery/cadquery

Ray casting On An Object with Holes

Open
#1,413 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

```
def raycast(pnt1: list[float, float, float], pnt2: list[float, float, float], shape: cq.Workplane()) -> dict:
shape_wrapped = shape.val()

intersection_pnts = {}

for e,f in enumerate(shape_wrapped.Faces()):
show_object(f.Wires())

surface = OCP.BRepAdaptor.BRepAdaptor_Surface(f.wrapped)

edge = OCP.BRepAdaptor.BRepAdaptor_Curve( OCP.BRepBuilderAPI.BRepBuilderAPI_MakeEdge(OCP.gp.gp_Pnt(*pnt1), OCP.gp.gp_Pnt(*pnt2)).Edge())

inter = OCP.IntCurveSurface.IntCurveSurface_HInter()

inter.Perform(edge, surface)

# print(inter.IsDone())
while not inter.IsDone():
print('Not Done')
pass

intersection_pnts[e] = {}

if inter.NbPoints() > 0:
for i in range(1, inter.NbPoints() + 1):
pnt = inter.Point(i).Pnt()
intersection_pnts[e][i] = (pnt.X(), pnt.Y(),pnt.Z())

return intersection_pnts

result = Workplane("XY").box(length,height,thickness).faces(">Z").workplane().hole(diam)\
.faces(">Z").workplane() \
.rect(length-padding,height-padding,forConstruction=True) \
.vertices().cboreHole(2.4,4.4,2.1)
ray = raycast([0,0,-10],[0,0,10],result)
```

Trying to do ray casting and through my research I came up with this code. The problem is that it seems to find collisions where there should be holes. When I run the code above it gives back a point at 0,0,-5 and 0,0,5 which are in the center hole and not on a face. Is there a way to account for this?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.