// Slices an object at a cut plane, and masks away everything that is on one side.
//
// Arguments:
// v = Normal of plane to slice at. Keeps everything on the side the normal points to. Default: [0,0,1] (UP)
// cp = If given as a scalar, moves the cut plane along the normal by the given amount. If given as a point, specifies a point on the cut plane. This can be used to shift where it slices the object at. Default: [0,0,0]
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
// planar = If true, this becomes a 2D operation. When planar, a `v` of `UP` or `DOWN` becomes equivalent of `BACK` and `FWD` respectively.
// Slices an object at a vertical Y-Z cut plane, and masks away everything that is right of it.
//
// Arguments:
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, OpenSCAD's preview rendering may be incorrect. Default: 10000
// x = The X coordinate of the cut-plane. Default: 0
// planar = If true, this becomes a 2D operation.
//
// Examples:
// left_half() sphere(r=20);
// left_half(x=-8) sphere(r=20);
// Example(2D):
// left_half(planar=true) circle(r=20);
moduleleft_half(s=1000,x=0,planar=false)
{
dir=LEFT;
difference(){
children();
translate([x,0,0]-dir*s/2){
if(planar){
square(s,center=true);
}else{
cube(s,center=true);
}
}
}
}
// Module: right_half()
//
// Usage:
// right_half([s], [x]) ...
// right_half(planar=true, [s], [x]) ...
//
// Description:
// Slices an object at a vertical Y-Z cut plane, and masks away everything that is left of it.
//
// Arguments:
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, OpenSCAD's preview rendering may be incorrect. Default: 10000
// x = The X coordinate of the cut-plane. Default: 0
// planar = If true, this becomes a 2D operation.
//
// Examples(FlatSpin):
// right_half() sphere(r=20);
// right_half(x=-5) sphere(r=20);
// Example(2D):
// right_half(planar=true) circle(r=20);
moduleright_half(s=1000,x=0,planar=false)
{
dir=RIGHT;
difference(){
children();
translate([x,0,0]-dir*s/2){
if(planar){
square(s,center=true);
}else{
cube(s,center=true);
}
}
}
}
// Module: front_half()
//
// Usage:
// front_half([s], [y]) ...
// front_half(planar=true, [s], [y]) ...
//
// Description:
// Slices an object at a vertical X-Z cut plane, and masks away everything that is behind it.
//
// Arguments:
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, OpenSCAD's preview rendering may be incorrect. Default: 10000
// y = The Y coordinate of the cut-plane. Default: 0
// planar = If true, this becomes a 2D operation.
//
// Examples(FlatSpin):
// front_half() sphere(r=20);
// front_half(y=5) sphere(r=20);
// Example(2D):
// front_half(planar=true) circle(r=20);
modulefront_half(s=1000,y=0,planar=false)
{
dir=FWD;
difference(){
children();
translate([0,y,0]-dir*s/2){
if(planar){
square(s,center=true);
}else{
cube(s,center=true);
}
}
}
}
// Module: back_half()
//
// Usage:
// back_half([s], [y]) ...
// back_half(planar=true, [s], [y]) ...
//
// Description:
// Slices an object at a vertical X-Z cut plane, and masks away everything that is in front of it.
//
// Arguments:
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, OpenSCAD's preview rendering may be incorrect. Default: 10000
// y = The Y coordinate of the cut-plane. Default: 0
// planar = If true, this becomes a 2D operation.
//
// Examples:
// back_half() sphere(r=20);
// back_half(y=8) sphere(r=20);
// Example(2D):
// back_half(planar=true) circle(r=20);
moduleback_half(s=1000,y=0,planar=false)
{
dir=BACK;
difference(){
children();
translate([0,y,0]-dir*s/2){
if(planar){
square(s,center=true);
}else{
cube(s,center=true);
}
}
}
}
// Module: bottom_half()
//
// Usage:
// bottom_half([s], [z]) ...
//
// Description:
// Slices an object at a horizontal X-Y cut plane, and masks away everything that is above it.
//
// Arguments:
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, OpenSCAD's preview rendering may be incorrect. Default: 10000
// z = The Z coordinate of the cut-plane. Default: 0
//
// Examples:
// bottom_half() sphere(r=20);
// bottom_half(z=-10) sphere(r=20);
modulebottom_half(s=1000,z=0)
{
dir=DOWN;
difference(){
children();
translate([0,0,z]-dir*s/2){
cube(s,center=true);
}
}
}
// Module: top_half()
//
// Usage:
// top_half([s], [z]) ...
//
// Description:
// Slices an object at a horizontal X-Y cut plane, and masks away everything that is below it.
//
// Arguments:
// s = Mask size to use. Use a number larger than twice your object's largest axis. If you make this too large, OpenSCAD's preview rendering may be incorrect. Default: 10000
// z = The Z coordinate of the cut-plane. Default: 0