gumyr / build123d

A python CAD programming library
Apache License 2.0
382 stars 72 forks source link

JernArc is not always co-planar with input plane #635

Closed jdegenstein closed 1 week ago

jdegenstein commented 4 weeks ago
someplane = Plane(
    origin=(-1.38, 42.48, 0.18), x_dir=(0.00, 0.00, 1.00), z_dir=(-0.26, 0.97, 0.30)
)
with BuildLine(someplane) as someline:
    zz = JernArc((0, 0), (0, 1), radius=20, arc_size=30)
print(zz.radius) #returns 2.0504554216551574 instead of 20.

image

The arbitrary input plane has a nonzero origin, and a nontrivial z-direction. This does not seem to be an issue for the built-in planes like Plane.XY, Plane.YZ, etc. The radius of the generated arc is wrong, as is the direction -- it is not co-planar with the local x,y of the input plane.

jdegenstein commented 1 week ago

Here is a simpler case that is also broken:

someplane3 = Plane(origin=(0, 0, 0.01), x_dir=(1, 0, 0), z_dir=(0, 0, 1))
with BuildLine(someplane3) as someline:
    zz = JernArc((0, 0), (1, 0), radius=20, arc_size=359)
print(zz.radius)  #returns 13.15... instead of 20

More investigation indicates that the localized tangent is wrong, as are the center point and end of arc.

jdegenstein commented 1 week ago

An even simpler broken example that is parallel to the XY plane:

someplane4 = Plane.XY
someplane4.origin = (0, 0, 1)
with BuildLine(someplane4) as someline:
    zz = JernArc((0, 0), (1, 0), radius=20, arc_size=359)
print(zz.radius) # returns 0.1745... instead of 20

from inside the JernArc class -- WorkplaneList.localize(tangent)=Vector: (1.0, 0.0, 1.0) which is incorrect, I believe a tangent (Vector) should NOT be affected by the Plane origin -- only by the x/z directions of the Plane.