Skip to content

Commit

Permalink
Final tweaks to the epsilons to make the loading and export corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Nov 18, 2024
1 parent f82ba8d commit a0e2e03
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/eu/mihosoft/vrl/v3d/CSG.java
Original file line number Diff line number Diff line change
Expand Up @@ -1663,8 +1663,8 @@ private CSG updatePolygons(ArrayList<Polygon> toAdd, ArrayList<Polygon> degenera
toAdd.add(poly);
}
} catch (Throwable ex) {
ex.printStackTrace();
System.err.println("Pruning bad polygon CSG::updatePolygons "+p);
//ex.printStackTrace();
progressMoniter.progressUpdate(1,1,"Pruning bad polygon CSG::updatePolygons "+p,null);
// try {PolygonUtil.concaveToConvex(p);} catch (Throwable ex2) {
// ex2.printStackTrace();
// }
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/eu/mihosoft/vrl/v3d/Vector3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
public class Vector3d extends javax.vecmath.Vector3d{


private static final double EXPORTEPSILON = 1.0e-10;
private static final String exportString = "%.16f";

private static final double EXPORTEPSILON = 1.0e-12;

/**
*
Expand Down Expand Up @@ -364,7 +366,7 @@ private double roundToEpsilon(double value,double epsilon) {
return ((double)Math.round(value / epsilon)) * epsilon;
}
private String roundedValue(double v,double ep) {
return String.format("%.16f", roundToEpsilon(v,ep));
return String.format(exportString, roundToEpsilon(v,ep));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static List<Polygon> concaveToConvex(Polygon incoming) {
Vector3d normal = concave.plane.getNormal().clone();

if (reorent) {
//System.err.println("\n\nIncoming polygon " + incoming);
// System.err.println("\n\nIncoming polygon " + incoming);
// reorent=true;
// double degreesToRotate = Math.toDegrees(Math.atan2(normalOfPlane.x, normalOfPlane.z));
// Transform orentation = new Transform().roty(degreesToRotate);
Expand Down Expand Up @@ -167,9 +167,9 @@ public static List<Polygon> concaveToConvex(Polygon incoming) {
concave = incoming.transformed(orentation3);
orentationInv = orentation3.inverse();
}
//System.err.println("Re-orenting polygon " + concave);
// System.err.println("Re-orenting polygon " + concave);
Polygon transformed = concave.transformed(orentationInv);
//System.err.println("corrected-orenting polygon " + transformed);
// System.err.println("corrected-orenting polygon " + transformed);
checkForValidPolyOrentation(normal, transformed);

}
Expand Down Expand Up @@ -234,7 +234,7 @@ public static List<Polygon> concaveToConvex(Polygon incoming) {
if (reorent) {
poly = poly.transform(orentationInv);

poly=checkForValidPolyOrentation(normal, poly);
poly = checkForValidPolyOrentation(normal, poly);
}
// poly.plane.setNormal(normalOfPlane);
poly.setColor(incoming.getColor());
Expand All @@ -259,8 +259,15 @@ private static Polygon checkForValidPolyOrentation(Vector3d normal, Polygon poly
List<Vector3d> points = poly.getPoints();
List<Vector3d> r = new ArrayList<>(points);
Collections.reverse(r);
poly = Polygon.fromPoints(r);
// throw new RuntimeException("Error, the reorentation of the polygon resulted in a different normal than the triangles produced from it");
Polygon fromPoints = Polygon.fromPoints(r);
double l = normal.minus( fromPoints.plane.getNormal()).length();
if (l > d * 10 && l < (2 - d)) {
// throw new RuntimeException(
// "Error, the reorentation of the polygon resulted in a different normal than the triangles produced from it");
}else {
poly=fromPoints;

}
}
return poly;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/eu/mihosoft/vrl/v3d/StlExportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void makeBadSTL() throws IOException {
CSG loaded = STL.file(file.toPath());
System.out.println("Perform difference");
badExport=loaded.scaleToMeasurmentX(160).scaleToMeasurmentY(30);
badExport=new Cube(180,40,10).toCSG().toZMin().toXMin().toYMin().movey(-5).difference(badExport);
badExport=new Cube(180,40,10).toCSG().toZMin().toXMin().toYMin().movey(-5).difference(badExport).rotx(35).roty(45);
FileUtil.write(Paths.get("TextStl2.stl"),
badExport.toStlString());
}
Expand Down

0 comments on commit a0e2e03

Please sign in to comment.