Skip to content
constructive solid geometry
Branch: master
Clone or download

README.md

jsolid is a java library for Constructive Solid Geometry that internally uses JCSG library which uses binary space partitioning algorithm. It's great for programmatically generating STL shapes for 3d printer.

Tutorial

To use jsolid you need download latest release jar. Whole API is available via static methods of JSolid class so all you need is to import it by adding following line (which is omitted for simplicity in all following examples). You may also want to add this line to favorites in your IDE.

import static com.perunlabs.jsolid.JSolid.*;

All curved (rounded) edges are approximated with finite precision, which is configured by specifying maximal distance allowed between required curve and closest point of approximated solid.

config().setCircleToPolygonPrecision(0.1);

Once you build your solid you can store it as STL file using

com.perunlabs.jsolid.d3.Stl.toStl(solid, "path/on/disk");

Examples

simple cuboid (preview)

cuboid(2, 4, 8);

cuboid with rounded corners (preview)

cuboid(5, 5, 5)
  .cornerR(z(), 1);

simple cylinder (preview)

cylinder(5, 10);

cylinder with many segments (preview)

cylinder(10, 2)
  .addSegment(5, 10)
  .addFunnel(3, 2)
  .addSegment(4);

rotated (preview)

cylinder(2, 10)
  .rotate(y(), degrees(45));

adding solids (preview)

cylinder(2, 10)
  .add(cuboid(10, 2, 5));

subtracting solids (preview)

cylinder(2, 10)
  .sub(cuboid(10, 2, 5));

intersecting solids (preview)

cylinder(2, 10)
  .intersect(cuboid(10, 2, 5));

adding with shift (preview)

cylinder(3, 1)
  .add(cuboid(6, 6, 1).moveBy(vx(5)));

subtracting with alignment (preview)

cuboid(4, 4, 4)
  .sub(cylinder(1, 1), align(maxZ()));

subtracting with two alignments (preview)

cuboid(4, 4, 4)
  .sub(cuboid(1, 1, 4), align(maxX()), align(minY()));

adding with outside alignment (preview)

cuboid(4, 4, 4)
  .add(cylinder(2, 4), alignOutside(maxZ()));

adding with outside alignment and margin (preview)

cuboid(4, 4, 4)
  .add(cylinder(2, 1), alignOutside(maxZ(), 2));

convex hull (preview)

cuboid(4, 4, 1)
  .add(cylinder(1, 1).moveBy(vx(5)))
  .convexHull();

prism with regular polygon as base (preview)

prism(regularPolygon(4, 8), 4);
You can’t perform that action at this time.