Skip to content

Latest commit

 

History

History
122 lines (108 loc) · 3.24 KB

positioning.md

File metadata and controls

122 lines (108 loc) · 3.24 KB

Positioning

Routines to quickly position 2D elements on the edges of a rectagular canvas on the XY-plane.


List of Functions

PTop( canvas ) position children on top of the canvas
PBottom( canvas ) position children at the bottom of the canvas, mirror of PTop()
PLeft( canvas ) position children on the left of the canvas
PRight( canvas ) position children on the right of the canvas, mirror of PLeft()
PFTop( canvas ) same as PTop() but flipped
PFBottom( canvas )same as PBottom() but flipped
PFLeft( canvas ) same as PLeft() but flipped
PFRight( canvas ) same as PRight() but flipped
MUp( offset ) move up
MDown( offset ) move down
MLeft( offset ) move left
MRight( offset ) move right

PTop( canvas, leftRight )

canvas height of canvas
leftRight = 0left/right offset, right+

PBottom( thickness, offset, leftRight, frontBack, faceIn )

canvas height of canvas
leftRight = 0left/right offset, right+

PLeft( canvas, upDown )

canvas width of canvas
upDown = 0up/down offset, up+

PRight( canvas, upDown )

canvas width of canvas
upDown = 0up/down offset, up+

MUp( offset, leftRight )

offset distance to move up
leftRight = 0left/right offset, right+

MDown( offset, leftRight )

offset distance to move down
leftRight = 0left/right offset, right+

MLeft( offset, upDown )

offset distance to move left
upDown = 0up/down offset, up+

MRight( offset, upDown )

offset distance to move right
upDown = 0up/down offset, up+

Sample Code

photo

cWidth  = 80;
cHeight = 100;

// normal top/left
// bottom/right - mirror
canvas();
target();
color("red")    PTop   (cHeight) target();
color("green")  PBottom(cHeight) target();
color("blue")   PLeft  (cWidth ) target();
color("orange") PRight (cWidth ) target();

// flipped top/left
// bottom/right - mirror
translate([120,0,0]) {
    canvas();
    target();
    color("red")    PFTop   (cHeight) target();
    color("green")  PFBottom(cHeight) target();
    color("blue")   PFLeft  (cWidth ) target();
    color("orange") PFRight (cWidth ) target();
}

// move only
translate([240,0,0]) {
    canvas();
    circle(5);
    color("red")    MUp   (20) circle(5);
    color("green")  MDown (20) circle(5);
    color("blue")   MLeft (20) circle(5);
    color("orange") MRight(20) circle(5);
}

module canvas() {
    color("gray")
    translate([0,0,-1])
    square([cWidth,cHeight],center=true);
    color("red") translate([0,0,1]) {
        square([cWidth,1],center=true);
        square([1,cHeight],center=true);
    }
}
module target() {
    linear_extrude(1)
    difference() {
        polygon([[-15,0],[15,0],[15,-15],[-15,-5]]);
        circle(3);
    }
}