2D Projections In OpenSCAD

But what about 2D manufacturing tools, such as laser cutters? OpenSCAD can be used to design for these as well. It has 2D objects and operations. But say you want to make a case out of acrlyic, and want to model it in 3D to make sure it all fits together properly, but you need to get each part as a 2D part to cut on the laser cutter. OpenSCAD will not let you export a 2D file (like DXF) from a 3D object. What do you do?

OpenSCAD has a projection() function that does what you need. It only has one parameter, called “cut” so it’s easy to use. Allow me to illustrate how it works:

If we make a cone and tilt it 45 degrees to make it less boring, we get this:

3D Cone Diagonal

The code:

rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}

(After typing code into the OpenSCAD window, you have to hit F6 to render the object.)

What’s going on:

cylinder() draws a cylinder. The parameters define the size of the cylinder. “r1” and “r2” define the size (radius) of the two ends. In this case, the tip radius is set to 0, so it becomes a cone. “h” defines the hight of the cylinder. “center=true” puts the center of the center of the cone at the XYZ origin.

rotate() tilts the cone. The “a” parameter defines the angle vector to rotate the cone. A group of numbers in square brackets (“[]”) is an array, and usually arrays of three values are XYZ vectors. In this case, the cone gets tilted 45 degrees clockwise around the Y axis.

In a 3D tool, you can change the direction in which you (the “camera”) looks at something. From the top, the cone has a very symmetrical appearance:

3D Cone Top

So how do you get from this 3D shape to a 2D image? There are multiple ways. You could just outline the outside from one point of view:

2D Projection cut=false

The code:

projection( cut=false ) {
rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}
}

What’s going on:

The cylinder() and rotate() functions are the same as before. All we’re doing is applying the projection() function. “cut=false” tells it to project the entire object to a 2D outline.

projection() projects your 3D object on the Z plane, which is the two dimentional plane created by the X and Y axes, and from which the Z axis projects perpendicularly.

The cut=false projection of the cone looks very much the same as the 3D cone as seen from above, just without any depth.

You can also take a cross-section at the Z plane. Imagine you sliced the cone at the Z plane – you would get something that looked like this:

3D Cone Conic Section

The code:

difference() {
rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}

translate( v=[0,0,50] ) {
cube( size=[100,100,100], center=true );
}
}

What’s going on:

This is an example of how 3D modeling is done in OpenSCAD. This new shape could be the tip of a needle or the top of a modern architecture building.

The cylinder is created as before, but a second shape is created using the cube() function.

cube() creates a cube, of course. The “size” vector determines how big it is, in this case 100 units on each side, which is the as big as the cone itself. The actual size here is unimportant, since we’re going to subtract the cube from the cone. “center” works the same as with the cylinder() function, centering the cube at the XYZ origin.

The translate() function moves the cube. “v” is a vector which describes in which direction and how far to move it. In this case, we’re moving it up 50 units. Since this is half the size of the cube vertically, it’s just moving the cube to sit on the Z plane.

difference() creates a new object that starts with the first (in this case the cone) and subtracts the second (the cube) and any subsequent objects (of which there are none in this case). So we end up with a cone that has been sliced off at the Z plane.

If you remember your geometry, circles, elipses, parabolas, and hyperbolas are all just slices of a cone, so the resulting shape at the slice is an elipse. The OpenSCAD 2D primitive circle() only makes circles, so you may want to use this process to create an elipse. to make that conic section elipse a 2D object, we can use the cut parameter in projection():

2D Projection cut=true

The code:

projection( cut=true ) {
rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}
}

What’s going on:

The only difference here is “cut=true”, which takes the cross-section of the 3D cone at the Z plane. Note that there is no cube object being created – that was just for illustration purposes. The slice is done by the projection() function.

The position of the 3D object is important in determining how projection() works.

If we move the cone up a bit using the translate() function:

3D Cone Higher

The code:

translate( v=[0,0,25] ) {
rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}
}

What’s going on:

This is the same as before, only we’re using translate() to move the cone up 25 units, the same was (though not as much) as we moved the cube above.

Doing a projection() from this with “cut=false” looks exactly the same as before we moved the cone:

2D Projection Higher cut=false

The code:

projection( cut=false ) {
translate( v=[0,0,25] ) {
rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}
}
}

Z positioning makes no impact on this kind of projection.  But taking the Z plane slice ends up with a very different shape:

2D Projection Higher cut=true

The code:

projection( cut=true ) {
translate( v=[0,0,25] ) {
rotate( a=[0,45,0] ) {
cylinder( r1=25, r2=0, h=100, center=true );
}
}
}

If our cone were infinitely long, this shape would be a different elipse than the one above. OpenSCAD doesn’t do infinite lengths, so the result looks more like a horseshoe. If the cone were tilted slightly more (and were infinitely long), the result would be a hyperbola.

Post a Comment

Your email is never shared. Required fields are marked *

*
*