by OJFord · 6y ago · 0 comments
I haven't actually played around with it yet, but surely it's just a matter of combining (or computing from) your (python) variables appropriately? And even having the ability to `assert x > 10` or whatever to validate allowable parameter ranges.
https://wiki.freecadweb.org/Sketcher_Workbench
e.g. Scripted CAD pseudocode:
x = param('length')
y = param('width')
z = 2*x + y
base = rect(x, y)
box = base.extrude(z)
radius = y/2 if y < x else x/2
cutout = circle(radius=radius, centre=(radius+base.x, radius+base.y)).extrude(z)
obj = box - cutout
The circle cutout inherently has tangent constraints on the sides of the box, without needing library support or a solver.I realise there are limits, I just think you could do a lot without hitting them, and when you do.. you're just programming, find a constraint solver to use.
Also, one doesnt usually just find a constraint solver to use. You'll want a geometric constraint solver which will be built on top of a non-linear algebraic constraint solver. It really needs to be integrated into the CAD system.
p, q, r = params("side1", "side2", "side3")
pq = arccos((p^2+q^2-r^2)/(2*p*q))
pr = # ... similar
qr = # ... similar
assert pq + pr + qr == 360, "Side lengths invalid"
pside = line((0,0), (p,0))
xy_qr = (r*cos(180-pr), r*sin(180-pr))
qside = line((p,0), xy_qr)
rside = line(xy_qr, (0,0))
triangle = sketch(pside, qside, rside)
Or whatever this fictional API is to look like.Obviously to do generic constraint solving, you need a generic constraint solver. My point is that if you have fixed known constraints, and a programming language, you can just compute what you want explicitly.