gumyr / build123d

A python CAD programming library
Apache License 2.0
515 stars 88 forks source link

DoubleTanchetArc fails due to axis is_parallel check #728

Open bikemike opened 1 week ago

bikemike commented 1 week ago

Below is some code that should produce DoubleTanchetArcs for each iteration but it fails 340 times out of 900 because of the parallel check on ~objects_curve.py:233. I'm not sure the best solution for this but reducing the tolerance to 5e-2 fixes it for the code below.

failcount = 0
for i in range(0,900):
    l1 = Rot(0,0,-45 + i/10) * Line((0,0),(10,0))
    l2 = Line((0,-10),(0,0))
    try:
        dta = DoubleTangentArc(l2@.5, l2%0, l1)
    except Exception as e:
        failcount+=1

print (f"failed {failcount} times")

If I change the code to use the cross product to check for parallel(below), I also get 340 failures when using 1e-5 as the tolerance. Increasing the tolerance to 2e-3 fixes.

t1 = other.tangent_at(p1)
t2 = circle.tangent_at(p2)
cross_mag = t1.cross(t2).length

if cross_mag < 2e-3:
    arc_centers.append(arc_center)
gumyr commented 1 week ago

Thanks for the testing. I found that I had to relax the value even further: if other_axis.is_parallel(circle_axis, 0.05): to get all of these tests to pass. I don't see a down side to this but if you do let me know.