Skip to content

Conversation

lenianiva
Copy link
Contributor

@lenianiva lenianiva commented Aug 28, 2025

Resolves #1868

This PR adds an optional initializer, which traverses through the constraint graph and locally solves every constraint with no degree of freedom. The traversal starts at fixed constraints. This provides a starting point for the solver to work with. If the constraint graph is a forest in which each tree has at most one fixed root, and each constraint has zero degree of freedom (e.g. axis with degree 0 or 180, or point), then this solves the constraints exactly.

Try this out:

import cadquery as Cq

def mk_marker() -> Cq.Solid:
    return Cq.Solid.makeSphere(2)
def mk_cube() -> Cq.Solid:
    return Cq.Solid.makeBox(1.5, 1.6, 1.7)

a = (
    Cq.Assembly()
    .add(mk_marker(), name="m1", loc=Cq.Location(-1, 0, 0))
    .add(mk_marker(), name="m2", loc=Cq.Location(0, 1, 0))
    .add(mk_marker(), name="m3", loc=Cq.Location(0, 0, 1))
    .add(mk_cube(), name="cube", loc=Cq.Location(0, 0, 0))
    .constrain("m1", "m2", "Point")
    .constrain("m2", "m3", "Point")
    .constrain("m3", "cube@faces@<Z", "Point")
    .solve(verbosity=5, tree_initialize=True)
)

with tree_initialize, the number of iteration drops from 11 to (...)

  • Implement tree traversal
  • Map each constraint point back to the object's location

@lenianiva lenianiva marked this pull request as ready for review August 31, 2025 05:15
@lenianiva lenianiva marked this pull request as draft August 31, 2025 18:34
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

Successfully merging this pull request may close these issues.

A faster assembly solver

1 participant