Skip to content

Instantly share code, notes, and snippets.

@arnholm
Last active January 11, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnholm/e9f44039aa389720dc63433e2a245cfa to your computer and use it in GitHub Desktop.
Save arnholm/e9f44039aa389720dc63433e2a245cfa to your computer and use it in GitHub Desktop.
AngelCAD code (angelscript) - generate solid from math functions
// AngelCAD
double f(double sign, double x, double n)
{
   double xn  = pow(x,n);
   double x1n = pow(1-x,n);
   return sign*(xn/(xn+x1n) + 0.5);
}

shape@ main_shape()
{
   double nv= 10;
   double n = 2;
   pos2d@[] v; 
   for(double i=0   ; i<nv; i++) { v.push_back(pos2d(i/nv,f(-1,i/nv,n))); };
   for(double i=nv-1; i>=0; i--) { v.push_back(pos2d(i/nv,f(+1,i/nv,n))); };
   return linear_extrude(scale(8,1)*polygon(v),0.1);
}

void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment