Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stl;
- /**
- * This program shows the basic shapes for 3D print
- * @author do_hoang
- * @version 1.3 2020-02-11
- */
- public class StlImage {
- private double minThick;
- private double thickScale;
- private double scale;
- private double maxValue;
- public StlImage (double min, double max){
- this.minThick = min;
- // this.maxValue = max;
- this.thickScale = max - min;
- this.scale = 0.1;
- }
- public Solid createSolid(int[][] matrix) {
- Solid solid = new Solid();
- //find the maximum value in the integer array, store it in maxValue
- for(int i = 0; i < matrix.length; i++) {
- for(int j = 0; j < matrix[i].length; j++) {
- if(matrix[i][j] >= maxValue) {
- maxValue = matrix[i][j];
- }
- }
- }
- for(int i = 0; i < matrix.length-1; i++) {
- for(int j = 0; j < matrix[i].length-1; j++) {
- //top
- solid.addFacet(
- createIfsVertex(i, j, matrix[i][j]),
- createIfsVertex(i+1, j, matrix[i+1][j]),
- createIfsVertex(i+1, j+1, matrix[i+1][j+1]),
- createIfsVertex(i, j+1, matrix[i][j+1]));
- }
- }
- int width = matrix.length;
- int length = matrix[0].length;
- //side1
- //add the four Vertex to Solid using addFacet
- solid.addFacet(
- new Vertex(0, 0, 0),
- new Vertex(width * scale, 0, 0),
- new Vertex(width * scale, 0, minThick),
- new Vertex(0, 0, minThick));
- //side2
- //add the four Vertex to Solid using addFacet
- solid.addFacet(
- new Vertex(0, length * scale, 0),
- new Vertex(0, 0, 0),
- new Vertex(0, 0, minThick),
- new Vertex(0, length * scale, minThick));
- //side3
- //add the four Vertex to Solid using addFacet
- solid.addFacet(
- new Vertex(width * scale, 0, 0),
- new Vertex(width * scale, length * scale, 0),
- new Vertex(width * scale, length * scale, minThick),
- new Vertex(width * scale, 0, minThick));
- //side4
- //add the four Vertex to Solid using addFacet
- solid.addFacet(
- new Vertex(width * scale, length * scale, 0),
- new Vertex(0, length * scale, 0),
- new Vertex(0, length * scale, minThick),
- new Vertex(width * scale, length * scale, minThick));
- //bottom
- //add the four Vertex to Solid using addFacet
- solid.addFacet(
- new Vertex(0, 0, 0),
- new Vertex(0, length * scale, 0),
- new Vertex(width * scale, length * scale, 0),
- new Vertex(width * scale, 0, 0));
- return solid;
- }
- private Vertex createIfsVertex(double x, double y, double z) {
- //calculate the thickness based on the following formula
- double thickness = minThick + thickScale * Math.sqrt(z/maxValue);
- //create a new Vertex with the following value
- return new Vertex(x * scale, y * scale, thickness);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement