Skip to content

Instantly share code, notes, and snippets.

@logiclrd
Created November 26, 2024 16:13
Show Gist options
  • Save logiclrd/cce0fe2e9edd7fc6c6292120b0e13832 to your computer and use it in GitHub Desktop.
Save logiclrd/cce0fe2e9edd7fc6c6292120b0e13832 to your computer and use it in GitHub Desktop.
Useful OpenSCAD Primitives
module sector(radius, angle)
{
fn = ($fn <= 0) ? 20 : $fn;
polygon(
[
[0, 0],
for (i = [0 : fn])
let (a = i * angle / fn)
[radius * cos(a), radius * sin(a)]
]);
}
module arc(radius1, radius2, angle)
{
fn = ($fn <= 0) ? 20 : $fn;
polygon(
[
for (i = [0 : fn])
let (a = i * angle / fn)
[radius1 * cos(a), radius1 * sin(a)],
for (i = [0 : fn])
let (a = (fn - i) * angle / fn)
[radius2 * cos(a), radius2 * sin(a)]
]);
}
module cone(inclination, sweep, slice = [0, 200])
{
rotate_extrude(angle = sweep)
polygon(
[
[0, slice[0]],
[slice[0] * sin(inclination), slice[0]],
[slice[1] * sin(inclination), slice[1]],
[0, slice[1]]
]);
}
@logiclrd
Copy link
Author

$fn = 100;

sector(20, 150);

arc(50, 55, 220, $fn = 10);

difference()
{
  cone(25, 180, [40, 50]);
  
  translate([0, 0, 5])
  cone(25, 360, [30, 50], $fn = 15);
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment