Closed huskier closed 6 months ago
.constrain("top@faces@<Z", "con_tl?X", "Plane")
is similar to:
.constrain("top", <the top>.faces("<Z").val(), "con_tl", <the con_tl>.faces(tag="X").val(), "Plane")
The "?" is used with tags. "con_tl?X" refers to the tag named "X" on connector part "con_tl".
This line adds a Plane constraint between the face selected on the top part and the face tagged with tag name "X" on the con_tl connector part.
there is a flaw (see the following screenshot) for the door display with the show function imported from cadquery.vis,
I reproduced this display issue and opened PR #1540.
Thank you for your reply and the PR, lorenzncode. @lorenzncode
This line adds a Plane constraint between the face selected on the top part and the face tagged with tag name "X" on the con_tl connector part.
My question is exactly here. The face selected on the top part is perpendicular to Z-axis, while the face tagged with tage name "X" on the con_tl connector part is perpendicular to X-axis. So, how to understand this Plane constraint? It is not the touch relationship.
For the following constraint, I understand that it means two face touching.
.constrain("left@faces@<Z", "con_bl?Z", "Plane")
For the following constraint, I understand that it means that don't let them rotate.
.constrain("top@faces@<Y", "con_tl@faces@>Y", "Axis")
The face selected on the top part is perpendicular to Z-axis, while the face tagged with tage name "X" on the con_tl connector part is perpendicular to X-axis. So, how to understand this Plane constraint?
Correct, initially these two faces are in different planes. The desired end result after solve
is that the two faces are in the same plane.
Thanks for your explanation. @lorenzncode
I still do not quite understand the constraint. Let me explain my point in detail.
# top
.constrain("top@faces@<Z", "con_tl?X", "Plane")
For the above code, "top@faces@<Z" indicates the plane XY-plane002.
while "con_tl?X" indicates the plane far most in X-direction parallel to the plane YZ-plane002
The plane XY-plane002 and the plane far most in X-direction parallel to the plane YZ-plane002 are orthogonal to each other. I think these two planes never touch each other.
The constraints are somewhat abstract for me.
See the docs on constraints and the constraint solver here: https://cadquery.readthedocs.io/en/latest/assy.html#constraints
When you call solve
it runs an optimization that iterates by automatically varying the component locations. The optimization attempts to satisfy all constraints.
Prior to optimization, it is quite typical for constraints to not be met. If all constraints were already met prior to optimization then there wouldn't be any reason to run the optimization.
Before optimization:
The top face and con_tl face are in different planes as shown in red, green.
After optimization:
The Plane constraint is satisfied.
@lorenzncode Thank you for your detailed explanation. I've gotten the point.
To simplified the constraints setting, I've firstly put all the parts in a pre-arranged layout, and then set the constraints in the new initial layout. I've opened a new thread (#1546) for the approach.
Hi, I do not quite understand the following several constraints extracted from the door assembly example. Could any one explain them a little bit? Thanks in advance.
BTW, I think the panel constraints may need one more in Y-direction. Otherwise, I think the panel is not fully constrained.
Besides, there is a flaw (see the following screenshot) for the door display with the show function imported from cadquery.vis, while the STEP model is correct.