Skip to content

Instantly share code, notes, and snippets.

@arnholm arnholm/wikipedia_csg.md
Last active May 6, 2019

Embed
What would you like to do?
AngelCAD code for Wikipedia CSG model

AngelCAD code for the model at https://en.wikipedia.org/wiki/Constructive_solid_geometry

// AngelCAD code sample: csg_wikipedia.as
// https://en.wikipedia.org/wiki/Constructive_solid_geometry
// https://arnholm.github.io/angelcad-docs/

shape@ main_shape()
{
   // intersection of cube and sphere
   cube@       cu = cube(size:45,center:true);
   sphere@     sp = sphere(r:30);
   solid@    cusp = cu & sp;     // '&' = intersection

   // union of 3 cylinders
   cylinder@  cy1 = cylinder(r:17,h:60,center:true);
   solid@     cy2 = rotate_x(deg:90)*cy1;
   solid@     cy3 = rotate_y(deg:90)*cy1; 
   solid@ cyl_all = cy1+cy2+cy3; // '+' = union

   // difference of the 2 above
   return cusp - cyl_all;        // '-' = difference
}

void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1);
}
@arnholm

This comment has been minimized.

Copy link
Owner Author

commented Sep 28, 2017

wikipedia_csg

@arnholm

This comment has been minimized.

Copy link
Owner Author

commented Sep 28, 2017

Result of AngelCAD code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.