Skip to content

Commit 1eb14fc

Browse files
authored
Merge pull request #1210 from lorenzncode/1159-docs
Update assembly constraint docs
2 parents e23f43d + d71458a commit 1eb14fc

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

doc/assy.rst

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,6 @@ STEP can be loaded in all CAD tool, e.g. in FreeCAD and the XML be used in other
370370
door.save('door.step')
371371
door.save('door.xml')
372372
373-
In the case of STEP colors are preserved but not transparency.
374-
375373
.. image:: _static/door_assy_freecad.png
376374

377375

@@ -389,9 +387,9 @@ Objects can be added to an assembly with initial locations supplied, such as:
389387
assy = cq.Assembly()
390388
assy.add(
391389
cone,
392-
loc=cq.Location(cq.Vector(0, 0, 0), cq.Vector(1, 0, 0), 180),
390+
loc=cq.Location((0, 0, 0), (1, 0, 0), 180),
393391
name="cone0",
394-
color=cq.Color("green")
392+
color=cq.Color("green"),
395393
)
396394
assy.add(cone, name="cone1", color=cq.Color("blue"))
397395

@@ -733,21 +731,21 @@ Where:
733731

734732
import cadquery as cq
735733

736-
b1 = cq.Workplane().box(1,1,1)
734+
b1 = cq.Workplane().box(1, 1, 1)
737735
b2 = cq.Workplane().sphere(0.15)
738736

739737
assy = (
740738
cq.Assembly()
741-
.add(b1,name='b1')
742-
.add(b2, loc=cq.Location(cq.Vector(0,0,4)), name='b2', color=cq.Color('red'))
739+
.add(b1, name="b1")
740+
.add(b2, loc=cq.Location((0, 0, 4)), name="b2", color=cq.Color("red"))
743741
)
744742

745743
# fix the position of b1
746-
assy.constrain('b1','Fixed')
744+
assy.constrain("b1", "Fixed")
747745
# b2 on one of the edges of b1
748-
assy.constrain('b2','b1@edges@>>Z and >>Y','PointOnLine')
746+
assy.constrain("b2", "b1@edges@>>Z and >>Y", "PointOnLine")
749747
# b2 on another of the edges of b1
750-
assy.constrain('b2','b1@edges@>>Z and >>X','PointOnLine')
748+
assy.constrain("b2", "b1@edges@>>Z and >>X", "PointOnLine")
751749
# effectively b2 will be constrained to be on the intersection of the two edges
752750

753751
assy.solve()
@@ -768,31 +766,31 @@ The cost function is:
768766
Where:
769767

770768
- :math:`\vec{ c }` is the center of the argument,
771-
- :math:`param` is the parameter of the constraint - tuple specifying the target position,
772-
- :math:`\operatorname{dist}( \vec{ a }, b)` is the distance between point :math:`\vec{ a }` and
773-
line :math:`b`.
769+
- :math:`param` is the parameter of the constraint - tuple specifying the target position.
774770

775771

776772
.. cadquery::
777773

778774
import cadquery as cq
779775

780-
b1 = cq.Workplane().box(1,1,1)
776+
b1 = cq.Workplane().box(1, 1, 1)
781777
b2 = cq.Workplane().sphere(0.15)
782778

783779
assy = (
784780
cq.Assembly()
785-
.add(b1,name='b1')
786-
.add(b2, loc=cq.Location(cq.Vector(0,0,4)), name='b2', color=cq.Color('red'))
781+
.add(b1, name="b1")
782+
.add(b2, loc=cq.Location((0, 0, 4)), name="b2", color=cq.Color("red"))
783+
.add(b1, loc=cq.Location((-2, 0, 0)), name="b3", color=cq.Color("red"))
787784
)
788785

786+
pnt = (0.5, 0.5, 0.5)
787+
789788
# fix the position of b1
790-
assy.constrain('b1','Fixed')
791-
# b2 on one of the edges of b1
792-
assy.constrain('b2','b1@edges@>>Z and >>Y','PointOnLine')
793-
# b2 on another of the edges of b1
794-
assy.constrain('b2','b1@edges@>>Z and >>X','PointOnLine')
795-
# effectively b2 will be constrained to be on the intersection of the two edges
789+
assy.constrain("b1", "Fixed")
790+
# fix b2 center at point
791+
assy.constrain("b2", "FixedPoint", pnt)
792+
# fix b3 vertex position at point
793+
assy.constrain("b3@vertices@<X and <Y and <Z", "FixedPoint", pnt)
796794

797795
assy.solve()
798796
show_object(assy)
@@ -801,7 +799,7 @@ Where:
801799
FixedRotation
802800
=============
803801

804-
FixedRotation fixes the rotation of the given argument to be equal to the value specified via the parameter of the constraint. The argument is rotated about it's origin firstly by the Z angle, then Y and finally X.
802+
FixedRotation fixes the rotation of the given argument to be equal to the value specified via the parameter of the constraint.
805803

806804
This constraint locks all rotational degrees of freedom of the argument.
807805
The cost function is:
@@ -821,21 +819,21 @@ Where:
821819

822820
import cadquery as cq
823821

824-
b1 = cq.Workplane().box(1,1,1)
825-
b2 = cq.Workplane().rect(0.1, 0.1).extrude(1,taper=-15)
822+
b1 = cq.Workplane().box(1, 1, 1)
823+
b2 = cq.Workplane().rect(0.1, 0.1).extrude(1, taper=-15)
826824

827825
assy = (
828826
cq.Assembly()
829-
.add(b1,name='b1')
830-
.add(b2, loc=cq.Location(cq.Vector(0,0,4)), name='b2', color=cq.Color('red'))
827+
.add(b1, name="b1")
828+
.add(b2, loc=cq.Location((0, 0, 4)), name="b2", color=cq.Color("red"))
831829
)
832830

833831
# fix the position of b1
834-
assy.constrain('b1','Fixed')
832+
assy.constrain("b1", "Fixed")
835833
# fix b2 bottom face position (but not rotation)
836-
assy.constrain('b2@faces@<Z','FixedPoint',(0,0,0.5))
834+
assy.constrain("b2@faces@<Z", "FixedPoint", (0, 0, 0.5))
837835
# fix b2 rotational degrees of freedom too
838-
assy.constrain('b2','FixedRotation',(45,0,45))
836+
assy.constrain("b2", "FixedRotation", (45, 0, 45))
839837

840838
assy.solve()
841839
show_object(assy)
@@ -862,21 +860,21 @@ Where:
862860

863861
import cadquery as cq
864862

865-
b1 = cq.Workplane().box(1,1,1)
866-
b2 = cq.Workplane().rect(0.1, 0.1).extrude(1,taper=-15)
863+
b1 = cq.Workplane().box(1, 1, 1)
864+
b2 = cq.Workplane().rect(0.1, 0.1).extrude(1, taper=-15)
867865

868866
assy = (
869867
cq.Assembly()
870-
.add(b1,name='b1')
871-
.add(b2, loc=cq.Location(cq.Vector(0,0,4)), name='b2', color=cq.Color('red'))
868+
.add(b1, name="b1")
869+
.add(b2, loc=cq.Location((0, 0, 4)), name="b2", color=cq.Color("red"))
872870
)
873871

874872
# fix the position of b1
875-
assy.constrain('b1','Fixed')
873+
assy.constrain("b1", "Fixed")
876874
# fix b2 bottom face position (but not rotation)
877-
assy.constrain('b2@faces@<Z','FixedPoint',(0,0,0.5))
875+
assy.constrain("b2@faces@<Z", "FixedPoint", (0, 0, 0.5))
878876
# fix b2 some rotational degrees of freedom too
879-
assy.constrain('b2@faces@>Z','FixedAxis',(1,0,2))
877+
assy.constrain("b2@faces@>Z", "FixedAxis", (1, 0, 2))
880878

881879
assy.solve()
882880
show_object(assy)

0 commit comments

Comments
 (0)