-
-
Save thehans/1791e1b8c6b40cc9841544e1a255c170 to your computer and use it in GitHub Desktop.
OpenSCAD "polygircle" based on superellipse / superformula equation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Number of sides | |
m = 3; // [1:1:8] | |
// Pointedness | |
p = 1; // [0:0.1:4] | |
// Inradius | |
r = 1; | |
// Larger m requires larger n1 for comparable pointedness | |
// scaling with m squared seems about right | |
// p=1 corresponds with canonical squircle (superellipse with n=4) | |
n1 = p/4*m*m; | |
// Ratios determined to give the flattest edges for a given m value | |
n_ratio = [16.01, 4, 1.779, 1, 0.632, 0.432, 0.311, 0.233][m-1]; | |
// If ratio is too large, the x coordinate can exceed the inradius then dip inward to form "dimples". | |
// Criteria for table values was the largest ratio which never exceeded r by some epsilon | |
// Tested with: p=40, $fn=8000, r=1 (high "pointedness", outside of typical range, makes dimples more apparent) | |
// https://en.wikipedia.org/wiki/Superformula | |
function superformula(m=4,n1=4,n2=4,n3=1,a=1,b=1) = [for(i=[0:1:$fn-1]) | |
let(th = i*360/$fn, R = (abs(cos(m/4*th)/a)^n2+abs(sin(m/4*th)/b)^n3)^(-1/n1)) | |
//echo(th, R*cos(th)) | |
//assert((th>20 && th<340) || R*cos(th)<=1.000001) // used to find n_ratio's | |
R*[cos(th), sin(th)] | |
]; | |
// subset of superformula, where a=b, and n2=n3 | |
function polygircle(m=4,n1=4,n=4,r=1) = superformula(m,n1,n,n,r,r); | |
polygon(polygircle(m=m,n1=n1,n=n1*n_ratio,r,$fn=200)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment