gumyr / build123d

A python CAD programming library
Apache License 2.0
402 stars 75 forks source link

Explicitly providing a plane to BuildLine() breaks model #212

Closed OvisMaximus closed 1 year ago

OvisMaximus commented 1 year ago

given the following code:

from build123d import *

with BuildPart(Plane.XZ) as p_builder:
    with BuildSketch(Plane.XZ) as s_builder:
        radius = 5
        with BuildLine(Plane.XZ) as shape:
#        with BuildLine() as shape:
            l1 = CenterArc((0, 0), radius, 180, 180)
            l2 = CenterArc((0, 10), radius, 0, 180)
            l3 = Line(l2 @ 1, l1 @ 0)
            l4 = Polyline(l1 @ 1, (0, 5), l2 @ 0)
        make_face()
    extrude(s_builder.sketch, -2)
debug(shape.line.wrapped)
show_object(p_builder.part.wrapped)

I get a ValueError: Cannot build face(s): wires not planar

When the comment of the BuildLine() line is moved to the other line, it renders just fine.

Expectation: according to documentation, for all Builders the default is to use the XY plane. In this situation this makes no sense, so I explicitly stated the plane I want to use to draw the sketch.

image

The observed behavior of the rendered model is what I expect - the plane of the sketch builder is adopted by the line builder. The observed behavior of the debug rendering is not what I expect because it is rendered on the default XY plane. Given that adopting the orientation (and location) of the surrounding builder as default overriding the XY default, it is also puzzeling that you will get a different orientation of the part when removing the explicit XZ plane in the constructor of the sketch builder:

image

Additional fun fact: when you replace l4 by a straight Line(l1 @ 1, l2 @ 0) both initialisations of BuildLine work out well.

gumyr commented 1 year ago

Thank you for raising this bug. The problem was actually in CenterArc - it wasn't being built on Plane.XZ which when combined with the Polyline with a point that was being placed on Plane.XZ (0, 5) resulted in a non-planar set of edges and therefore the above error message. CenterArc has been fixed now so the line is built on Plane.XZ which results in the desired end shape: image

As you use build123d, if you see anything else that doesn't look right please raise another issue(s).