Can you chamfer on a curved surface?

65 views
Skip to first unread message

Dan Christian

unread,
Aug 31, 2022, 6:44:36 PM8/31/22
to CadQuery
I'm trying to chamfer the eye sockets of a simple head.

If I uncomment the chamfer line in the code below, it shows two edges selected, but I get command not done.  I'm guessing this is because I'm trying to chamfer a curved surface.  Is that possible?  Is there another way to do it (ideally with a curved edge instead of a bevel)?

The example is based on Rodger's code from the other day.

Thanks,
Dan

import cadquery as cq

head_height = 120
head_width2 = 50
eye_height = 20
eye_offset = 40
eye_depth = 15

def eyesocket():
    obj = cq.Workplane("XY").box(eye_height, 2.5 * eye_depth, head_width2 / 2)
    obj = obj.translate([eye_height / 2, -head_width2 / 2, eye_depth / 2])
    obj = obj.rotate((0, 0, 0), (1, 0, 0), 180)
    obj = obj.translate([-eye_offset, 2, head_width2])
    return obj

sock = eyesocket()
#show_object(sock, options={"alpha":0.8, "color": (123, 164, 223)})

head = cq.Workplane("XZ").lineTo(head_width2, 0)
head = head.ellipseArc(head_width2, head_height, angle1=0, angle2=90).close()
head = head.revolve(180, axisStart=(0, 0, 0), axisEnd=(0, 1, 0))
head = head.cut(sock)
head = head.cut(sock.translate((1.5 * eye_offset, 0, 0)))

print("Head has %r edges" % head.edges(">Y").size())
#head = head.chamfer(2)

show_object(head, options={"alpha":0.2, "color": (223, 223, 164)})

Dan Christian

unread,
Aug 31, 2022, 6:55:42 PM8/31/22
to CadQuery
I found my bug.  Apparently you can.
The following code works:
import cadquery as cq

head_height = 120
head_width2 = 50
eye_height = 20
eye_offset = 40
eye_depth = 15

def eyesocket():
    obj = cq.Workplane("XY").box(eye_height, 2.5 * eye_depth, head_width2 / 2)
    obj = obj.translate([eye_height / 2, -head_width2 / 2, eye_depth / 2])
    obj = obj.rotate((0, 0, 0), (1, 0, 0), 180)
    obj = obj.translate([-eye_offset, 2, head_width2])
    return obj

sock = eyesocket()
#show_object(sock, options={"alpha":0.8, "color": (123, 164, 223)})

head = cq.Workplane("XZ").lineTo(head_width2, 0)
head = head.ellipseArc(head_width2, head_height, angle1=0, angle2=90).close()
head = head.revolve(180, axisStart=(0, 0, 0), axisEnd=(0, 1, 0))
head = head.cut(sock)
head = head.cut(sock.translate((1.5 * eye_offset, 0, 0)))

sel = "(not <Y) and (not <Z)"
print("Head has %r %s edges" % (head.edges(sel).size(), sel))
head = head.edges(sel).chamfer(2)
if head.findSolid().isValid():
    print("head not valid")


show_object(head, options={"alpha":0.2, "color": (223, 223, 164)})

Dan Christian

unread,
Aug 31, 2022, 7:24:28 PM8/31/22
to CadQuery
I can't get consistent results.
If I use the string selector below (if True), it finds 24 edges and works.  If I use the box selector, then it also finds 24 edges, but gives "command not done".

Of course, this is a simplified version of the real code, which never works.

Any debug tips?
Dan

import cadquery as cq

head_height = 120
head_width2 = 50
eye_height = 20
eye_offset = 40
eye_depth = 15

def eyesocket():
    obj = cq.Workplane("XY").box(eye_height, 2.5 * eye_depth, head_width2 / 2)
    obj = obj.translate([eye_height / 2, -head_width2 / 2, eye_depth / 2])
    obj = obj.rotate((0, 0, 0), (1, 0, 0), 180)
    obj = obj.translate([-eye_offset, 2, head_width2])
    return obj

sock = eyesocket()
#show_object(sock, options={"alpha":0.8, "color": (123, 164, 223)})

head = cq.Workplane("XZ").lineTo(head_width2, 0)
head = head.ellipseArc(head_width2, head_height, angle1=0, angle2=90).close()
head = head.revolve(180, axisStart=(0, 0, 0), axisEnd=(0, 1, 0))
head = head.cut(sock)
head = head.cut(sock.translate((1.5 * eye_offset, 0, 0)))

if head.findSolid().isValid():
    print("head pre not valid")

if False:

    sel = "(not <Y) and (not <Z)"
else:
    sel = cq.selectors.BoxSelector(
        (-head_width2, 1, 0),
        (head_width2, 0.99*head_width2, 0.8*head_height),
        boundingbox=True)                      # select just eye edges


print("Head has %r %s edges" % (head.edges(sel).size(), sel))
head = head.edges(sel).chamfer(2)
if head.findSolid().isValid():
    print("head post not valid")


show_object(head, options={"alpha":0.2, "color": (223, 223, 164)})

Lorenz Neureuter

unread,
Aug 31, 2022, 10:48:05 PM8/31/22
to Dan Christian, CadQuery
I find that both of your selection methods work when followed by chamfer if the chamfer value is small enough.  They begin to fail at different values though likely due to different edge ordering.

In your real code, does the chamfer work if you reduce the value?

--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/CAEcGQ%2BOacQ-e2NRKFT4gvVkvk5Lpw8%3DMEOB7OivmE4umK4xxNQ%40mail.gmail.com.

Dan Christian

unread,
Sep 1, 2022, 6:54:30 PM9/1/22
to CadQuery
So the chamfer is failing if it doesn't have enough room to work.  That makes sense.

The fancy version has lines that intersect due to the fancier eye sockets intersection with the ellipsoid surface.  So even tiny chamfers fail when the face tapers to 0.  I'm just trying to round things to avoid sharp edges, but there isn't a "just be sloppy and don't worry about it" mode.

Is there a better way to round edges?

Thanks for the help,
Dan

Roger Maitland

unread,
Sep 2, 2022, 9:55:04 PM9/2/22
to Dan Christian, CadQuery
It certainly is possible to chamfer curved edges.  Here is how I chamfered the sockets:
head = (
cq.Workplane("XZ")
.lineTo(head_width2, 0)
.ellipseArc(head_width2, head_height, angle1=0, angle2=90)
.close()
.revolve(360, axisStart=(0, 0, 0), axisEnd=(0, 1, 0))
.cut(sock)
.cut(sock.translate((1.5 * eye_offset, 0, 0)))
.faces("not %Plane")
.edges("not <Z")
.edges("not <Y")
.chamfer(1)
)
image.png
However, chamfer (and fillet) are complex and very dependent on the edges/values selected - a value of 1 is about the largest I could get to work here. What seems like it should work sometimes doesn't and results in the OpenCascade error.

Cheers,
Roger

--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages