CadQuery/cadquery

`cskHole` generates incorrect results for shallow holes

Opened this issue · 1 comments

cadquery/cadquery/cq.py

Lines 2930 to 2988 in 3cd327a

def cskHole(
self: T,
diameter: float,
cskDiameter: float,
cskAngle: float,
depth: Optional[float] = None,
clean: bool = True,
) -> T:
"""
Makes a countersunk hole for each item on the stack.
:param diameter: the diameter of the hole
:type diameter: float > 0
:param cskDiameter: the diameter of the countersink, must be greater than hole diameter
:param cskAngle: angle of the countersink, in degrees ( 82 is common )
:type cskAngle: float > 0
:param depth: the depth of the hole
:type depth: float > 0 or None to drill thru the entire part.
:param clean: call :meth:`clean` afterwards to have a clean shape
The surface of the hole is at the current workplane.
One hole is created for each item on the stack. A very common use case is to use a
construction rectangle to define the centers of a set of holes, like so::
s = (
Workplane()
.box(2, 4, 0.5)
.faces(">Z")
.workplane()
.rect(1.5, 3.5, forConstruction=True)
.vertices()
.cskHole(0.125, 0.25, 82, depth=None)
)
This sample creates a plate with a set of holes at the corners.
**Plugin Note**: this is one example of the power of plugins. CounterSunk holes are quite
time consuming to create, but are quite easily defined by users.
see :meth:`cboreHole` to make counterbores instead of countersinks
"""
if depth is None:
depth = self.largestDimension()
boreDir = Vector(0, 0, -1)
center = Vector()
# first make the hole
hole = Solid.makeCylinder(
diameter / 2.0, depth, center, boreDir
) # local coords!
r = cskDiameter / 2.0
h = r / math.tan(math.radians(cskAngle / 2.0))
csk = Solid.makeCone(r, 0.0, h, center, boreDir)
res = hole.fuse(csk)
return self.cutEach(lambda loc: res.moved(loc), True, clean)

If the cone generated by the angle and diameter is taller than the depth of the hole, it still cuts through and forms a conical cutout where I think it should be truncated.

I'll add more details soon, and am also happy to submit a PR myself unless someone beats me to it!

@TheLostLambda Could you post a screenshot for more context?