eu.mihosoft.vrl.v3d.samples.EdgeTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcsg Show documentation
Show all versions of jcsg Show documentation
Java implementation of BSP based CSG (Constructive Solid Geometry)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package eu.mihosoft.vrl.v3d.samples;
import eu.mihosoft.vrl.v3d.CSG;
import eu.mihosoft.vrl.v3d.Cylinder;
import eu.mihosoft.vrl.v3d.Edge;
import eu.mihosoft.vrl.v3d.FileUtil;
import eu.mihosoft.vrl.v3d.Polygon;
import eu.mihosoft.vrl.v3d.Sphere;
import static eu.mihosoft.vrl.v3d.Transform.unity;
import eu.mihosoft.vrl.v3d.Vector3d;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Average Chicken Egg.
*
* @author Michael Hoffer <[email protected]>
*/
public class EdgeTest {
public CSG toCSG(boolean optimized) {
double radius = 22;
double stretch = 1.50;
int resolution = 64;
CSG cylinder = new Cylinder(1, 0.3, 8).toCSG();
CSG sphere = new Sphere(0.1, 8, 4).toCSG().transformed(unity().translateZ(0.15));
CSG cyl = new Cylinder(0.08, 0.3, 8).toCSG();
// CSG csg = cylinder.difference(cyl).union(sphere);
CSG csg = cylinder.difference(cyl);
// CSG csg = cylinder.union(sphere);
if (!optimized) {
return csg;
} else {
List boundaryPolygons = Edge.boundaryPolygons(csg);
System.out.println("#groups: " + boundaryPolygons.size());
// List polys = boundaryPolygons.stream().peek(p->System.out.println("verts: "+p.vertices)).map(p->PolygonUtil.concaveToConvex(p)).flatMap(pList->pList.stream()).collect(Collectors.toList());
return CSG.fromPolygons(boundaryPolygons);
}
// return csg;
}
public static void main(String[] args) throws IOException {
FileUtil.write(Paths.get("edge-test.stl"), new EdgeTest().toCSG(true).toStlString());
FileUtil.write(Paths.get("edge-test-orig.stl"), new EdgeTest().toCSG(false).toStlString());
}
}