Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using z3 to solve constraints? #135

Closed
songcq opened this issue Feb 9, 2020 · 4 comments
Closed

Using z3 to solve constraints? #135

songcq opened this issue Feb 9, 2020 · 4 comments

Comments

@songcq
Copy link

songcq commented Feb 9, 2020

Hi, I'm using z3py solver in my projects to solve 2D constraints like

  • a circle has to go through a point
  • a circle has to be tangent to some line
  • a circle has to be tangent to another circle
  • intersection points between lines, circles etc

and we should be able to combine them in arbitrary way. They're useful for finding tangent line/circle and defining fillets (concave fillets can not be constructed using minkowski).

With z3 solver these problems become much easier solve. I'm considering to extract my code into a module and submit to SolidPython, but that means SolidPython will depend on z3. Is that dependency fine or something we should try to avoid?

Thanks

@etjones
Copy link
Contributor

etjones commented Feb 9, 2020

I'm definitely open to adding dependencies if they add new capacities. It sounds like z3py might do that for sure.

I think there's an easier solution for your particular fillet issues (example below), but I'm a little intrigued by the z3py system. Do you have any more examples of how we might use it?

In your specific example though, have you looked at offset() at all? I was working on some filleted stuff recently and realized it is much more capable than I thought.

Here's an example of a concave 2D fillet:

#! /usr/bin/env python

from solid import *
SEGMENTS = 48

def concave_fillet():
    points = (
        (0,0),
        (1,0),
        (1,1),
        (0.5, 0.25),
        (0,1)
    )

    fillet_rad = 0.1
    concave = offset(r=-fillet_rad)(
        offset(r=fillet_rad)(
            polygon(points)
        )
    )

    return concave

if __name__ == '__main__':
    a = concave_fillet()
    out_path = scad_render_to_file(a, file_header='$fn = %s;' % SEGMENTS, include_orig_code=True)
    print(f'Wrote file to {out_path}')

@songcq
Copy link
Author

songcq commented Feb 10, 2020

Thank you, your method using offset worked for me. Btw should offset take a segments arguments? The global SEGMENTS doesn't work for me.

I'll keep playing with z3 and maybe show you some more examples in the future.

@etjones
Copy link
Contributor

etjones commented Feb 10, 2020

I’m glad that’s working for you! I’ll have to look into the segments issue. SolidPython’s offset() doesn’t take an explicit segments argument, but it should. In general, the clause file_header='$fn = %s;' % SEGMENTS in the scad_render_to_file() call should enforce the fineness of curves, but I’ll run the attached code again and verify that.

@etjones etjones closed this as completed Feb 10, 2020
@songcq
Copy link
Author

songcq commented Feb 11, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants