Designing 3D objects tends to require a fair amount of algebra, if your skills in this regard are a bit rusty (or you are a little lazy or you want to verify your results) then the Online Equation Solver is the tool for you.

Describing an Arc

This site will take an equation (with multiple variables) and provide a solution for the variable you specify. The best way to illustrate this is with an example, in this case an OpenSCAD module to generate an arc, or more specifically a solid portion of a cylinder that describes a 180 degree arc with a given width and height. The first image shows the variables involved - in this case we know what W and H are, we need to know R to be able to create the object.

From Pythagoras' theorem we can see that R^2 is equal to (R - H) ^ 2 + (W / 2) ^ 2 (hypotenuse squared = sum of both sides squared), we need to solve this for R. You can do this youself or you can punch the formula into the equation solver as the equation field and then enter the variable you want to solve for (R) in the variables field. Click the Solve button and you get your answer (R = (W^2 + 4 * H^2) / (8 * H) in this case). The results are shown in the next image.

Here is some example OpenSCAD code that uses the resulting formula to create an arc from a cylinder (this example also creates a rectangular solid to compare against):

 /** Create an arc      *      * The middle of the base is at origin (0, 0, 0) and the tip of the arc      * points along the Y axis. Depth is in the Z axis and is centered on      * the origin.      */     module arc(width, height, depth = 2) {       radius = ((width * width) + (4 * height * height)) / (8 * height);       difference() {         translate(v = [ 0, -(radius - height), 0 ]) {           cylinder(h = depth, r = radius, center = true);           }         translate(v = [ 0, -radius, 0 ]) {           cube(size = [ radius * 2, radius * 2, depth ], center = true);           }         }       // Show a reference cube to make sure our arc is correct       translate(v = [ 0, height / 2, -(depth * 2) ]) {         cube(size = [ width, height, depth ], center = true);         }       }

The results look like the image to the left. I've updated my

``` /---------------------------------------------------------------------------- * Defines common constants used throughout the AutoSCAD libraries. ----------------------------------------------------------------------------- ----------------------------------------------------------------------------/

//--- Constants

/** The value of Pi */ PI = 3.1415926535897932;

/** Printer resolution (in mm) */ RESOLUTION = 0.3;

/** Base size for objects (in mm) * * The library is designed to generate things in 'units' - this defines the * size of a unit (in mm). */ BASE_SIZE = 2;

//--- Modules

/** Create an isosceles triangle * * The middle of the base is at origin (0, 0, 0) and the tip of the triangle * points along the Y axis. Depth is in the Z axis and is centered on the * origin. If depth is not specified it defaults to 2 units. */ module triangle(width, height, depth = 2) { angle = atan(height / (width / 2)); difference() { translate(v = [ 0, height / 2, 0 ]) { cube(size = [ width, height, depth ], center = true); } translate(v = [ width / 2, 0, 0 ]) { rotate(a = [ 0, 0, 90 - angle ]) { translate(v = [ width / 2, height, 0 ]) { cube(size = [ width, height * 2, depth * 2 ], center = true); } } } translate(v = [ -width / 2, 0, 0 ]) { rotate(a = [ 0, 0, 270 + angle ]) { translate(v = [ -width / 2, height, 0 ]) { cube(size = [ width, height * 2, depth * 2 ], center = true); } } } } }

/** Create an arc * * Creates a slice of a cylinder that is 'width' along the X axis, 'height' * along the Y axis and 'depth' along the Z axis. The base (the flat part) * is centered on the origin. If 'depth' is not specified it defaults to * 2 units. */ module arc(width, height, depth = 2) { radius = ((width * width) + (4 * height * height)) / (8 * height); difference() { translate(v = [ 0, -(radius - height), 0 ]) { cylinder(h = depth, r = radius, center = true, $fs = RESOLUTION); } translate(v = [ 0, -radius, 0 ]) { cube(size = [ radius * 2, radius * 2, depth * 2 ], center = true); } } }

/** Calculates the height of a teardrop with a given radius */ function teardroplength(tdradius) = tdradius + sqrt(2 * (tdradius * td_radius));

/** Generate a teardrop shape * * These shapes are useful for minimising print volume while maintaining * structural strength. */ module teardrop(tdradius, tdheight = 1) { translate(v = [ 0, -(teardroplength(tdradius) - tdradius), 0 ]) { rotate(a = [ 0, 0, 45 ]) { linearextrude(height = tdheight) { union() { circle(r = tdradius, $fs = RESOLUTION); square(size = [ tdradius, tdradius ]); } } } } }

/** Variation of the teardrop with a specified length * * This module allows you to specify the length of the teardrop shape as well * as the radius. */ module teardropscaled(tdradius, tdlength, tdheight = 1) { scalefactor = tdlength / teardroplength(tdradius); scale(v = [ 1, scalefactor, 1 ]) { teardrop(tdradius, td_height); } }

/** Create a hexagon. * * The 'size' parameter specifies the distance from the center of the * hexagon to the center of one of the six straight edges. The 'depth' * parameter specifies the size in the Z axis. The resulting object * is centered on the origin. */ module hexagon(length, depth = 2) { width = 2 * length * tan(30); union() { cube(size = [ length * 2, width, depth ], center = true); rotate(a = [ 0, 0, 60 ]) { cube(size = [ length * 2, width, depth ], center = true); } rotate(a = [ 0, 0, -60 ]) { cube(size = [ length * 2, width, depth ], center = true); } } }

/** Create a hexagon * * The 'radius' parameter specifies the radius of the smallest circle * that contains the hexagon. The 'depth' parameter specifies the size * in the Z axis. The resulting object is centered on the origin. */ module hexagonR(radius, depth = 2) { hexagon(radius * cos(30), depth); }

/** Create a hexagon * * This version of the hexagon module creates a hexagon where each * edge is of 'part' length. The 'depth' parameter specifies the * size in the Z axis. The resulting object is centered on the * origin. */ module hexagonL(part, depth = 2) { hexagon((part / 2) / tan(30), depth); }

/** Create a rounded rectangle */ module roundrect(width, height, depth, radius) { union() { // Make the four corner pieces translate(v = [ width / 2 - radius, height / 2 - radius, 0 ]) { cylinder(r = radius, h = depth, center = true); } translate(v = [ width / 2 - radius, -(height / 2 - radius), 0 ]) { cylinder(r = radius, h = depth, center = true); } translate(v = [ -(width / 2 - radius), height / 2 - radius, 0 ]) { cylinder(r = radius, h = depth, center = true); } translate(v = [ -(width / 2 - radius), -(height / 2 - radius), 0 ]) { cylinder(r = radius, h = depth, center = true); } // Add the center rectangles cube(size = [ width - (2 * radius), height, depth ], center = true); cube(size = [ width, height - (2 * radius), depth ], center = true); } } ```

to include the new arc module.