-
Notifications
You must be signed in to change notification settings - Fork 153
Tutorial Attachment Align
You may have noticed that with position() and orient(), specifying the
child anchors to position objects flush with their parent can be
annoying, or sometimes even tricky. You can simplify this task by
using the align() module. This module positions children on faces
of a parent and aligns to edges or corners, while picking the correct anchor points on
the children so that the children line up correctly with the
parent. Like position()
, align does not change the orientation of
the child object.
In the simplest case, if you want to place a child on the RIGHT side of its parent, you need to anchor the child to its LEFT anchor:
include<BOSL2/std.scad>
cuboid([50,40,15])
position(RIGHT)
color("lightblue")cuboid(5,anchor=LEFT);
When you use align() it automatically determines the correct anchor to use for the child and this anchor overrides any anchor specified to the child: any anchor you specify for the child is ignored.
include<BOSL2/std.scad>
cuboid([50,40,15])
align(RIGHT)
color("lightblue")cuboid(5);
To place the child on top of the parent in the corner you can do use align as shown below instead of specifying the RIGHT+FRONT+BOT anchor with position():
include<BOSL2/std.scad>
cuboid([50,40,15])
align(TOP,RIGHT+FRONT)
color("lightblue")prismoid([10,5],[7,4],height=4);
Both position() and align() can accept a list of anchor locations and makes several copies of the children, but if you want the children positioned flush, each copy requires a different anchor, so it is impossible to do this with a single call to position(), but easily done using align():
include<BOSL2/std.scad>
cuboid([50,40,15])
align(TOP,[RIGHT,LEFT])
color("lightblue")prismoid([10,5],[7,4],height=4);
If you want the children close to the edge but not actually flush you
can use the inset=
parameter of align to achieve this:
include<BOSL2/std.scad>
cuboid([50,40,15])
align(TOP,[FWD,RIGHT,LEFT,BACK],inset=3)
color("lightblue")prismoid([10,5],[7,4],height=4);
If you spin the children then align will still do the right thing
include<BOSL2/std.scad>
cuboid([50,40,15])
align(TOP,[RIGHT,LEFT])
color("lightblue")prismoid([10,5],[7,4],height=4,spin=90);
If you orient the object DOWN it will be attached from its top anchor, correctly aligned.
include<BOSL2/std.scad>
cuboid([50,40,15])
align(TOP,RIGHT)
color("lightblue")prismoid([10,5],[7,4],height=4,orient=DOWN);
Note that align() never changes the orientation of the children. If you put the blue prismoid on the right side the anchors line up but the edges of the child and parent don't.
include<BOSL2/std.scad>
prismoid(50,30,25){
align(RIGHT,TOP)
color("lightblue")prismoid([10,5],[7,4],height=4);
}
If you apply spin that is not a multiple of 90 degrees then alignment will line up the corner
include<BOSL2/std.scad>
cuboid([50,40,15])
align(TOP,RIGHT)
color("lightblue")cuboid(8,spin=33);
You can also attach objects to a cylinder. If you use the usual cubic anchors then a cube will attach on a face as shown here:
include<BOSL2/std.scad>
cyl(h=20,d=10,$fn=128)
align(RIGHT,TOP)
color("lightblue")cuboid(5);
But with a cylinder you can choose an arbitrary horizontal angle for the anchor. If you do this, similar to the case of arbitrary spin, the cube will attach on the nearest corner.
include<BOSL2/std.scad>
cyl(h=20,d=10,$fn=128)
align([1,.3],TOP)
color("lightblue")cuboid(5);
Table of Contents
Function Index
Topics Index
Glossary
Cheat Sheet
Tutorials
Basic Modeling:
- constants.scad STD
- transforms.scad STD
- attachments.scad STD
- shapes2d.scad STD
- shapes3d.scad STD
- drawing.scad STD
- masks2d.scad STD
- masks3d.scad STD
- distributors.scad STD
- color.scad STD
- partitions.scad STD
- miscellaneous.scad STD
Advanced Modeling:
- paths.scad STD
- regions.scad STD
- skin.scad STD
- vnf.scad STD
- beziers.scad STD
- nurbs.scad
- rounding.scad STD
- turtle3d.scad
- isosurface.scad
Math:
- math.scad STD
- linalg.scad STD
- vectors.scad STD
- coords.scad STD
- geometry.scad STD
- trigonometry.scad STD
Data Management:
- version.scad STD
- comparisons.scad STD
- lists.scad STD
- utility.scad STD
- strings.scad STD
- structs.scad STD
- fnliterals.scad
Threaded Parts:
Parts:
- ball_bearings.scad
- cubetruss.scad
- gears.scad
- hinges.scad
- joiners.scad
- linear_bearings.scad
- modular_hose.scad
- nema_steppers.scad
- polyhedra.scad
- sliders.scad
- tripod_mounts.scad
- walls.scad
- wiring.scad
STD = Included in std.scad