-
Notifications
You must be signed in to change notification settings - Fork 53
Primitive Solids
[[TOC]]
The keywords, if not the syntax, for primitives is usually quite close to what you can find in Openscad.
important All the code below lets you create different type of solids, but it does NOT draw them : to draw an object you created use:
assembly.add(myObject)
You can find out more about this in the The assembly|basics section.
Creates a cube at the origin of the coordinate system. When center is true the cube will be centered on the origin, otherwise it is created in the first octant.
size: Decimal or 3 value array. If a single number is given, the result will be a cube with sides of that length. If a 3 value array is given, then the values will correspond to the lengths of the X, Y, and Z sides. Default size is 1.
center: Either a boolean or an array :
- if "true", will center the cube
- if you pass in an array of integer/float values, it will center the cube at the specified coordinates
- you can also use arrays of booleans : [true, true, false] to specify on which axes the cube should be centered,
- or even mixed arrays like so [false,true,25] : which would not center the cube on the x axis, center it on the y axis, and put its z axis center at 25
Examples:
cube = new Cube({size:100})
or
cube = new Cube
center: [0,-100,50]
size: [100, 100, 100]
r: Decimal. This is the radius of the sphere.
d: Decimal. This is the diameter of the sphere :alternative to specifying the radius.
center: if an array is specified will center the sphere at the specified coordinates see "centering" for more details
$fn: Set the resolution/quality of the sphere
Example:
sphere = new Sphere
r: 25
$fn: 30
return sphere
or
sphere = new Sphere({r:10,center:[25,75.3,12]})
## Cylinder/Cone
h: This is the height of the cylinder. Default value is 1.
r: Decimal. The radius of both top and bottom ends of the cylinder. Use this parameter if you want plain cylinder. Default value is 1.
r1: Decimal. This is the radius of the cone on bottom end. Default value is 1.
r2: Decimal. This is the radius of the cone on top end. Default value is 1.
d: Decimal. This is the diameter of the cylinder :alternative to specifying the radius.
d1: Decimal. This is the diameter of the cone on bottom end. Default value is 1.
d2: Decimal. This is the diameter of the cone on top end. Default value is 1.
center: Either a boolean or an array : if true, will center the cylinder, if array, will center the cylinder at the specified coordinated
Example:
cylinder = new Cylinder
h: 128
r1:100
r2:50
center:true
return cylinder
# 2D Solids
All these shapes can be manipulated with the usual translate, rotate ,union etc, but need to be extruded to be combined with other 3d shapes.
By default, when you add a 2d shape to the assembly, it will automagically get extruded vertically by 1 unit
## Circle A 2d circle, whose size is settable via radius/diameter.
r: Decimal. This is the radius of the circle.
d: Decimal. This is the diameter of the circle :alternative to specifying the radius.
center: if an array is specified will center the circle at the specified coordinates
$fn: Set the resolution/quality of the circle
Example:
circle = new Circle
r: 25
$fn: 30
return circle
or
circle = new Circle({r:25, $fn:30})
## Rectangle A simple 2d rectangle or square
size: Decimal or 2 dimensional array. If the size is specified as a decimal value, it will produce a square. A 2 dimensional array will produce a rectangle.
center: [optional] If unspecified, the rectangle lower left corner of the rectangle will be placed at [0, 0]. If center is specified as boolean true, the center of the rectangle will be placed at [0, 0]. If an array is specified the rectangle will be centered at the specified coordinates.
Example:
rectangle = new Rectangle
size: [25, 50]
center: true
or a square
square = new Rectangle
size: 75
center: [100,150]
#Simplified API From v0.31 onwards, CoffeeSCad now also has a simplified api for drawing basic geometry:
for cubes:
cube1=cube({size:10, center:[-25,-25,0]})
the above is the same as
cube1 = new Cube({size:20,center:[-25,-25,0]})
assembly.add(cube1)
for spheres:
sphere1 = sphere({r:10})
the above is the same as
sphere1 = new Sphere({r:10})
assembly.add(sphere1)
same goes for cylinders
cylinder1 = cylinder({r:10,h:20,center:[0,30,0]})
circles
circle2 = circle({r:10,center:10})
and rectangles
rectangle1 = rectangle({size:10,center:[-20,30]})
for all the helpers above, the options you pass are the same as you would to their normal constructors
you can also pass in a second parameter (besides the options hash) to set the object's parent for example
redCube = cube({size:30,center:[-50,-50,0]}).color([1,0,0])
see here
greenSphere = sphere({r:20,center:-50,50},redCube).color([0,1,0])
the green sphere's parent is the red cube
###Important: this makes cube, sphere, cylinder, rectangle and circle reserved keywords! Don't redefine them in your code , or you will run into issues when trying to use these shorthands