OpenSCAD User Manual/Transformations
|
|
The text in its current form is incomplete. |
scale [edit]
Scales its child elements using the specified vector. The argument name is optional.
Usage Example:
scale(v = [x, y, z]) { ... }
cube(10); translate([15,0,0]) scale([0.5,1,2]) cube(10);
resize [edit]
In versions >= 2013.05, the resize() command is available. It modifes the size of the child object to match the given x,y, and z.
Usage Example: resize(newsize=[30,60,10]) sphere(r=10); // resize the sphere to extend 30 in x, 60 in y, and 10 in the z directions.
If x,y, or z is 0 then that dimension is left as-is.
resize([2,2,0]) cube(); // resize the 1x1x1 cube to 2x2x1
If the 'auto' parameter is set to true, it will auto-scale any 0-dimensions to match. For example.
resize([7,0,0], auto=true) cube([1,2,0.5]); // resize the 1x2x0.5 cube to 7x14x3.5
The 'auto' parameter can also be used if you only wish to auto-scale a single dimension, and leave the other as-is.
resize([10,0,0], auto=[true,true,false]) cube([5,4,1]); // resize to 10x8x1. Note that the z dimension is left alone.
rotate [edit]
Rotates its child a degrees about the origin of the coordinate system or around an arbitrary axis. The argument names are optional if the arguments are given in the same order as specified above.
When a rotation is specified for multiple axes the the rotation is applied in the following order: x, y, z.
Usage:
rotate(a = deg, v = [x, y, z]) { ... }
For example, to flip an object upside-down, you might do this:
rotate(a=[0,180,0]) { ... }
The above example will rotate your object 180 degrees around the 'y' axis.
The optional argument 'v' allows you to set an arbitrary axis about which the object will be rotated.
Example with arbitrary origin.
rotate(a=45, v=[1,1,0]) { ... }
This example will rotate your object 45 degrees around the axis defined by the vector [1,1,0] i.e. 45 around X and 45 around Y.
translate [edit]
Translates (moves) its child elements along the specified vector. The argument name is optional.
IExample
translate(v = [x, y, z]) { ... }
cube(2,center = true); translate([5,0,0]) sphere(1,center = true);
mirror [edit]
Mirrors the child element on a plane through the origin. The argument to mirror() is the normal vector on that plane.
Usage example:
mirror([ 0, 1, 0 ]) { ... }
rotate([0,0,10]) cube([3,2,1]); mirror([1,0,0]) translate([1,0,0]) rotate([0,0,10]) cube([3,2,1]);
multmatrix [edit]
Multiplies the geometry of all child elements with the given 4x4 transformation matrix.
Usage: multmatrix(m = [...]) { ... }
Example (translates by [10, 20, 30]):
multmatrix(m = [ [1, 0, 0, 10],
[0, 1, 0, 20],
[0, 0, 1, 30],
[0, 0, 0, 1]
]) cylinder();
Example (rotates by 45 degrees in XY plane and translates by [10,20,30]):
angle=45;
multmatrix(m = [ [cos(angle), -sin(angle), 0, 10],
[sin(angle), cos(angle), 0, 20],
[0, 0, 1, 30],
[0, 0, 0, 1]
]) union() {
cylinder(r=10.0,h=10,center=false);
cube(size=[10,10,10],center=false);
}
color [edit]
Displays the child elements using the specified RGB color + alpha value. This is only used for the F5 preview as CGAL and STL (F6) do not currently support color. The alpha value will default to 1.0 (opaque) if not specified.
Usage example:
color([r, g, b, a]) { ... }
Note that the r, g, b, a values are limited to floating point values in the range { 0.0 ... 1.0 } rather than the more traditional integers { 0 ... 255 }. However you can specify the values as fractions, e.g. for R,G,B integers in {0 ... 255} you can use:
color([ R/255, G/255, B/255 ]) { ... }
As of the 2011.12 version, colors can also be chosen by name; name is not case sensitive. For example, to create a red sphere, you can use this code:
color("red") sphere(5);
Alpha is also available with named colors:
color("Blue",0.5) cube(5);
The available color names are taken from the World Wide Web consortium's SVG color list. A chart of the color names is as follows:
|
|
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Chart based on "Web Colors" from Wikipedia
minkowski [edit]
Displays the minkowski sum of child nodes.
Usage example:
Say you have a flat box, and you want a rounded edge. There are many ways to do this, but minkowski is very elegant. Take your box, and a cylinder:
$fn=50; cube([10,10,1]); cylinder(r=2,h=1);
Then, do a minkowski sum of them:
$fn=50;
minkowski()
{
cube([10,10,1]);
cylinder(r=2,h=1);
}
hull [edit]
Displays the convex hull of child nodes.
Usage example:
hull() {
translate([15,10,0]) circle(10);
circle(10);
}
The