Skip to content

Instantly share code, notes, and snippets.

@arnholm
Last active September 6, 2017 07:17
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/8e5e9ebb25b65babbf5a696942dff19e to your computer and use it in GitHub Desktop.
Save arnholm/8e5e9ebb25b65babbf5a696942dff19e to your computer and use it in GitHub Desktop.

Drop with sweep (AngelCAD source code)

double pi = 4.0*atan(1.0);

// radius and height
double r(double t) { return 0.5*(1-cos(pi*t))*sin(pi*t) + 0.005; }
double z(double t) { return 80 + 80*cos(pi*t); }

// profile direction 
vec3d@ dir(double t, double exp) 
{
   double ang = pi*pow((1-t),exp);
   return vec3d(cos(ang)*r(t),sin(ang)*r(t),0);
}

// profile to sweep
shape2d@ profile(uint deg)
{
   double radius = 100;
   pos2d@[] prof_points;
   for(uint iang=0; iang<360; iang += deg) {
      double ang = pi*iang/180;
      prof_points.push_back(pos2d(radius*cos(ang),radius*sin(ang)));
   }
   return polygon(prof_points);
}

// sweep path
spline_path@ path(uint incr, double twist)
{
   pos3d@[] path_points;
   vec3d@[] path_dir;
   for(uint i=0; i<100; i+=incr) {
      double t = i*0.01;
      path_points.push_back(pos3d(0,0,z(t)));
      path_dir.push_back(dir(t,twist));
   }
   return spline_path(path_points,path_dir);
}

shape@ main_shape()
{
   return sweep(profile(deg:30),path(incr:3,twist:3));
}

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