Skip to content

Instantly share code, notes, and snippets.

@arnholm
Last active June 17, 2019 06:57
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/30348680c1c46ee8a195f06926ad9669 to your computer and use it in GitHub Desktop.
Save arnholm/30348680c1c46ee8a195f06926ad9669 to your computer and use it in GitHub Desktop.

We use AngelCAD to generate OpenSCAD input :-)

Generate a polygon witn N sides, from an array of positions

// AngelCAD code: openscad_polygon.as
shape@ main_shape()
{
   // build an array from np points
   array<pos2d@> p;
   double rad = 25;
   uint np = 16;
   for(uint i=0;i<np;i++) {
      double angle = i*2*PI/np;
      p.push_back(rad*pos2d(cos(angle),sin(angle)));
   }
   
   // create a polygon
   return polygon(p);
}

void main()
{
   shape@ obj = main_shape();
   
   // instead of the usual xcsg, write an OpenSCAD .csg file: openscad_polygon.csg
   obj.write_csg(GetInputFullPath());
}
// This file was created using AngelCAD (as_csg) v1.3-01
// Copyright(C) 2015-2018 Carsten Arnholm, http://arnholm.org/
// Open it with OpenSCAD for display or further processing
$fn = 60;
$fa = 6.0;
$fs = 1.0;
group() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
polygon( points=[[25,0],[23.0969876051,9.5670863986],[17.6776692271,17.6776692271],[9.56708565354,23.0969876051],[-1.09278470717e-006,25],[-9.56708490849,23.0969890952],[-17.6776692271,17.6776692271],[-23.0969876051,9.56708714366],[-25,-2.18556941434e-006],[-23.0969876051,-9.56708565354],[-17.6776707172,-17.677667737],[-9.56708937883,-23.0969876051],[2.98122015963e-007,-25],[9.56709012389,-23.096986115],[17.677667737,-17.6776722074],[23.0969890952,-9.56708565354]] );
}
}
module custom_polygon()
{
// include file generated by AngelCAD
include <2_openscad_polygon.csg>
}
custom_polygon();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment