All examples run on MRJ 2.2.
example source.
public static boolean Example1() { Jun3dPoint[] points = new Jun3dPoint[20]; Random randomStream = new Random(); for (int i = 0; i < points.length; i++) { Jun3dPoint point = new Jun3dPoint(randomStream.nextDouble(), randomStream.nextDouble(), randomStream.nextDouble()); points[i] = point; } Jun3dBoundingBall boundingBall = Jun3dBoundingBall.FromPoints_(points); Vector aCollection = new Vector(points.length); for (int i = 0; i < points.length; i++) { JunOpenGL3dVertex aJunOpenGL3dVertex = JunOpenGL3dVertex.Point_(points[i]); aJunOpenGL3dVertex.size_(4); aJunOpenGL3dVertex.paint_(Color.black); aCollection.addElement(aJunOpenGL3dVertex); } JunOpenGL3dCompoundObject openGLObject = JunOpenGL3dCompoundObject.Components_(aCollection); JunOpenGL3dCompoundObject openGLBall = (JunOpenGL3dCompoundObject) JunOpenGL3dObject.Globe_radius_center_(15, boundingBall.radius(), boundingBall.center()); openGLBall.paint_(Color.blue); JunOpenGLStipple stipple = JunOpenGLStipple.Halftone_(0.25); for (int each = 0; each < openGLBall.components().length; each++) { openGLBall.components()[each].stipple_(stipple); } openGLObject.add_(openGLBall); openGLObject.show(); //return boundingBall return true; }
example source.
public static boolean Example1() { try { JunMetaballSolid solid; JunMetaSphere ball1, ball2, ball3; Jun3dPoint aPoint; solid = new JunMetaballSolid(); solid.threshold_(1.0d); aPoint = new Jun3dPoint(0.0 , 0.0, 0.0); ball1 = JunMetaSphere.Center_order_weight_(aPoint, 2, 0.4); aPoint = new Jun3dPoint(0.0 , 0.0 , 1.0); ball2 = JunMetaSphere.Center_order_weight_(aPoint, 2, 0.4); aPoint = new Jun3dPoint(0.0 , 0.0 , -1.0); ball3 = JunMetaSphere.Center_order_weight_(aPoint, 2, 0.4); solid.add_(ball1); solid.add_(ball2); solid.add_(ball3); StInterval xInterval = new StInterval(-2, 2, 0.2); StInterval yInterval = new StInterval(-2, 2, 0.2); StInterval zInterval = new StInterval(-2, 2, 0.2); JunOpenGL3dObject aJunOpenGL3dObject = solid.asJunOpenGL3dObjectXInterval_yInterval_zInterval_(xInterval, yInterval, zInterval); aJunOpenGL3dObject.paint_(Color.white); aJunOpenGL3dObject.show(); //return solid; return true; } catch (Exception e) { e.printStackTrace(); return false; } }
left: JunMetaballSolid, right: JunOpenGL3dObject.
example source.
public static boolean Example2() { try { JunMetaballSolid solid; JunMetaSphere cray, finger; Jun3dPoint aPoint; solid = JunMetaballSolid.Threshold_(1.0d); aPoint = new Jun3dPoint(0.0 , 0.0 , 0.0); cray = JunMetaSphere.Center_order_weight_(aPoint, 2, 1.0); aPoint = new Jun3dPoint(1.0 , 0.0 , 0.0); finger = JunMetaSphere.Center_order_weight_(aPoint, 8, -0.1); JunOpenGL3dObject smallJunOpenGL3dObject, largeJunOpenGL3dObject; largeJunOpenGL3dObject = JunOpenGL3dObject.Sphere_radius_(15, 1); largeJunOpenGL3dObject.paint_(Color.blue); aPoint = new Jun3dPoint(1.0 , 0.0 , 0.0); smallJunOpenGL3dObject = JunOpenGL3dObject.Sphere_radius_center_(15, 0.1, aPoint); smallJunOpenGL3dObject.paint_(Color.red); JunOpenGL3dCompoundObject.With_with_(largeJunOpenGL3dObject, smallJunOpenGL3dObject).show(); solid.add_(cray); solid.add_(finger); StInterval xInterval = StInterval.From_to_by_(-2, 2, 0.2); StInterval yInterval = StInterval.From_to_by_(-2, 2, 0.2); StInterval zInterval = StInterval.From_to_by_(-2, 2, 0.2); JunOpenGL3dObject aJunOpenGL3dObject = solid.asJunOpenGL3dObjectXInterval_yInterval_zInterval_(xInterval, yInterval, zInterval); aJunOpenGL3dObject.paint_(Color.blue); aJunOpenGL3dObject.show(); //return solid; return true; } catch (Exception e) { e.printStackTrace(); return false; } }
left: trace, right: triangles.
example source.
public static boolean Example3() { Vector dots = new Vector(); Random randomStream = new Random(); for (int i = 0; i < 50; i++) { dots.addElement(new Jun2dPoint(randomStream.nextDouble(), randomStream.nextDouble())); } JunVoronoi2dProcessor voronoi = JunVoronoi2dProcessor.Dots_(dots); voronoi.trace_(true); Frame frame = new Frame("JunVoronoi2dProcessor Trace Display"); frame.setSize(JunVoronoi2dProcessor.defaultDimension); frame.setResizable(false); frame.add(voronoi.canvas()); frame.pack(); frame.show(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); voronoi.compute(); System.out.println("area: " + voronoi.area()); Graphics gc = null; StImage anImage = new StImage(300, 300); Image newImage = SystemResourceSupport.createImage(anImage.width(), anImage.height()); try { Jun2dPoint[][] triangles = voronoi.triangles(); gc = newImage.getGraphics(); gc.setColor(Color.white); gc.fillRect(0, 0, newImage.getWidth(null), newImage.getHeight(null)); Point scale = new Point(200, 200); Point translation = new Point(50, 50); Rectangle box = new Rectangle(new Point(0, 0), new Dimension(1, 1)); box.x *= scale.x; box.y *= scale.y; box.width *= scale.x; box.height *= scale.y; box.x += translation.x; box.y += translation.y; gc.setColor(Color.red); gc.drawRect(box.x, box.y, box.width, box.height); for (int i = 0; i < triangles.length; i++) { Jun2dPoint[] points = triangles[i]; int[] xPoints = new int[points.length + 1]; int[] yPoints = new int[points.length + 1]; for (int j = 0; j < points.length; j++) { Jun2dPoint point = points[j]; if (point != null) { xPoints[j] = (int) (point.x() * scale.x + translation.x); yPoints[j] = (int) (point.y() * scale.y + translation.y); } } xPoints[points.length] = xPoints[0]; yPoints[points.length] = yPoints[0]; gc.setColor(Color.black); gc.drawPolyline(xPoints, yPoints, xPoints.length); } (new StImage(newImage))._display(); } finally { gc.dispose(); newImage.flush(); } //return voronoi; return true; }
example source.
public static boolean Example8() { //area: 3.1256671980047d System.out.println("This is a low precision example."); final Vector dots = new Vector(); final int step = 10; dots.addElement(new Jun2dPoint(0.0d, 0.0d)); StInterval interval = StInterval.From_to_by_(0, 360, step); interval.do_(new StBlockClosure() { public Object value_(Object valueObject) { double degrees = ((Double) valueObject).doubleValue(); double x = Math.cos(JunAngle._DegreesToRadians(degrees)); double y = Math.sin(JunAngle._DegreesToRadians(degrees)); dots.addElement(new Jun2dPoint(x, y)); x = Math.cos(JunAngle._DegreesToRadians(degrees + step / 2)); y = Math.sin(JunAngle._DegreesToRadians(degrees + step / 2)); dots.addElement(new Jun2dPoint(x * 0.5, y * 0.5)); return null; }; }); JunVoronoi2dProcessor voronoi = JunVoronoi2dProcessor.Dots_(dots); voronoi.trace_(true); Frame frame = new Frame("JunVoronoi2dProcessor Trace Display"); frame.setSize(JunVoronoi2dProcessor.defaultDimension); frame.setResizable(false); frame.add(voronoi.canvas()); frame.pack(); frame.show(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); voronoi.compute(); System.out.println("area: " + voronoi.area()); Graphics gc = null; StImage anImage = new StImage(300, 300); Image newImage = SystemResourceSupport.createImage(anImage.width(), anImage.height()); try { Jun2dPoint[][] triangles = voronoi.triangles(); gc = newImage.getGraphics(); gc.setColor(Color.white); gc.fillRect(0, 0, newImage.getWidth(null), newImage.getHeight(null)); Point scale = new Point(100, 100); Point translation = new Point(150, 150); Point origin = new Point(-1, -1); Rectangle box = new Rectangle(origin, new Dimension(1 - origin.x, 1 - origin.y)); box.x *= scale.x; box.y *= scale.y; box.width *= scale.x; box.height *= scale.y; box.x += translation.x; box.y += translation.y; gc.setColor(Color.red); gc.drawRect(box.x, box.y, box.width, box.height); for (int i = 0; i < triangles.length; i++) { Jun2dPoint[] points = triangles[i]; int[] xPoints = new int[points.length + 1]; int[] yPoints = new int[points.length + 1]; for (int j = 0; j < points.length; j++) { Jun2dPoint point = points[j]; if (point != null) { xPoints[j] = (int) (point.x() * scale.x + translation.x); yPoints[j] = (int) (point.y() * scale.y + translation.y); } } xPoints[points.length] = xPoints[0]; yPoints[points.length] = yPoints[0]; gc.setColor(Color.black); gc.drawPolyline(xPoints, yPoints, xPoints.length); } (new StImage(newImage))._display(); } finally { gc.dispose(); newImage.flush(); } //return voronoi; return true; }
example source.
public static boolean Example1b() { final JunVoronoi2dDiagram diagram = new JunVoronoi2dDiagram(new Jun2dPoint(200, 200)); diagram.displayCircle_(true); final Random random = new Random(); Canvas canvas = new Canvas() { public void paint(Graphics g) { g.drawImage(diagram.asImage(), 0, 0, null); return; } public void displayOn_(Graphics g) { this.paint(g); return; } }; canvas.setSize(diagram.extentByDimension()); Frame frame = new Frame(diagram.labelString()); frame.add(canvas); frame.pack(); frame.show(); frame.setResizable(false); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); for (int i = 0; i < 50; i++) { diagram.add_(new Jun2dPoint(random.nextDouble(), random.nextDouble()).scaledBy_(diagram.extent())); diagram.displayOn_(canvas.getGraphics()); } System.out.println("area: " + diagram.area()); return true; }
example source.
public static boolean Example6() { System.out.println("This is a low precision example."); final JunVoronoi2dDiagram diagram = new JunVoronoi2dDiagram(new Jun2dPoint(200, 200)); final Vector dots = new Vector(); final int step = 10; dots.addElement(new Jun2dPoint(0.0d, 0.0d)); StInterval interval = StInterval.From_to_by_(0, 360, step); interval.do_(new StBlockClosure() { public Object value_(Object valueObject) { double degrees = ((Double) valueObject).doubleValue(); double x = Math.cos(JunAngle._DegreesToRadians(degrees)); double y = Math.sin(JunAngle._DegreesToRadians(degrees)); dots.addElement(new Jun2dPoint(x, y)); x = Math.cos(JunAngle._DegreesToRadians(degrees + step / 2)); y = Math.sin(JunAngle._DegreesToRadians(degrees + step / 2)); dots.addElement(new Jun2dPoint(x * 0.5, y * 0.5)); return null; } }); for (Enumeration e = dots.elements(); e.hasMoreElements(); ) { Jun2dPoint dot = (Jun2dPoint) e.nextElement(); diagram.add_( dot.plus_(1).scaledBy_(diagram.extent().dividedBy_(2)) ); } Frame window = JunDisplayModel.Visual_(diagram.asImage()).open(); window.setTitle(diagram.labelString()); window.setResizable(false); System.out.println("area: " + diagram.area()); return true; }
left: DelaunayDiagram, right: diagram.asVoronoiDiagram().
example source.
public static boolean Example2() { final JunDelaunay2dDiagram diagram = new JunDelaunay2dDiagram(new Jun2dPoint(200, 200)); Random random = new Random(); for (int i = 0; i < 50; i++) { diagram.add_(new Jun2dPoint(random.nextDouble(), random.nextDouble()).scaledBy_(diagram.extent())); } Canvas canvas = new Canvas() { public void paint(Graphics g) { g.drawImage(diagram.asImage(), 0, 0, null); return; } public void displayOn_(Graphics g) { this.paint(g); return; } }; canvas.setSize(diagram.extentByDimension()); Frame window1 = JunDisplayModel.Visual_(diagram.asImage()).open(); window1.setTitle(diagram.labelString()); window1.setResizable(false); Canvas canvas2 = new Canvas() { public void paint(Graphics g) { g.drawImage(diagram.asVoronoiDiagram().asImage(), 0, 0, null); return; } public void displayOn_(Graphics g) { this.paint(g); return; } }; canvas2.setSize(diagram.extentByDimension()); Frame window2 = JunDisplayModel.Visual_(diagram.asVoronoiDiagram().asImage()).open(); window2.setTitle(diagram.asVoronoiDiagram().labelString()); window2.setResizable(false); System.out.println("area: " + diagram.area()); return true; }
example source.
public static boolean Example5() { System.out.println("This is a low precision example."); final JunDelaunay2dDiagram diagram = new JunDelaunay2dDiagram(new Jun2dPoint(200, 200)); final int roundTimes = 10; int count = 0; for (int i = 0; i <= roundTimes; i++) { for (int j = 0; j <= roundTimes; j++) { if (count % 2 == 0) { diagram.add_((new Jun2dPoint((double) j / 10, (double) i / 10)).scaledBy_(diagram.extent())); } count++; } } Canvas canvas = new Canvas() { public void paint(Graphics g) { g.drawImage(diagram.asImage(), 0, 0, null); return; } public void displayOn_(Graphics g) { this.paint(g); return; } }; canvas.setSize(diagram.extentByDimension()); Frame window = JunDisplayModel.Visual_(diagram.asImage()).open(); window.setTitle(diagram.labelString()); window.setResizable(false); System.out.println("area: " + diagram.area()); return true; }