How to Make an Arc or Wedge in OpenSCAD

OpenSCAD apparently doesn’t have an easy way to make an arc or wedge, or any way to do a partial rotate_extrude. This presented a problem when I started to design my Parametric Encoder Wheel, because in order for it to look nice, it would need to have lots of extruded arcs or partial rotate extrudes in order to make the holes.

Encoder Wheel, OpenSCAD Arc
Creating an Arc with OpenSCAD

Here’s how I solved the problem. Currently this will render slots up to 180 degrees around, but extending it should be pretty easy. If you’re doing a lot of these in your model, be sure to use render(), or badness will occur.


/* 
 * Excerpt from... 
 * 
 * Parametric Encoder Wheel 
 *
 * by Alex Franke (codecreations), March 2012
 * http://www.theFrankes.com
 * 
 * Licenced under Creative Commons Attribution - Non-Commercial - Share Alike 3.0 
*/

module arc( height, depth, radius, degrees ) {
	// This dies a horible death if it's not rendered here 
	// -- sucks up all memory and spins out of control 
	render() {
		difference() {
			// Outer ring
			rotate_extrude($fn = 100)
				translate([radius - height, 0, 0])
					square([height,depth]);
		
			// Cut half off
			translate([0,-(radius+1),-.5]) 
				cube ([radius+1,(radius+1)*2,depth+1]);
		
			// Cover the other half as necessary
			rotate([0,0,180-degrees])
			translate([0,-(radius+1),-.5]) 
				cube ([radius+1,(radius+1)*2,depth+1]);
		
		}
	}
}

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

8 Comments

  1. Hi
    I’m new to openscad and 3d printing. Your arc code snippet saved me quite a bit of time thanks
    Dave

  2. I am a teacher of blind and low-vision students. This OpenSCAD module will help me very much in helping them to understand concepts regarding volumes of revolution in calculus. This is far superior to just offering a description. Thanks!

  3. For some reason, it renders as 1x1x1 cylinder -1/4. No matter what values I assign to the variables, it always returns the same shape. Any feedback?

Leave a Reply to David AllanCancel Reply

Your email address will not be published. Required fields are marked *