private void initOriginal() throws Exception { int size = 500000; float x; float y; float z; float a; Coord3d[] points = new Coord3d[size]; Color[] colors = new Color[size]; Random r = new Random(); r.setSeed(0); for (int i = 0; i < size; i++) { x = r.nextFloat() - 0.5f; y = r.nextFloat() - 0.5f; z = r.nextFloat() - 0.5f; points[i] = new Coord3d(x, y, z); a = 0.25f; colors[i] = new Color(x, y, z, a); } Scatter scatter = new Scatter(points, colors); chart = AWTChartComponentFactory.chart(Quality.Advanced, "newt"); chart.getScene().add(scatter); }
private void initSample() throws Exception { Coord3d[] points = readSample("/Users/jwjoubert/Documents/r/MATSim-SA/digicore/data/sample.csv"); /* Get the centroid of the data set. */ double sumX = 0.0; double sumY = 0.0; double sumZ = 0.0; for (Coord3d c : points) { sumX += c.x; sumY += c.y; sumZ += c.z; } double cX = sumX / (double) points.length; double cY = sumY / (double) points.length; double cZ = sumZ / (double) points.length; Coord3d centroid = new Coord3d(cX, cY, cZ); /* Report the mean. */ LOG.info(String.format("Mean X: %.2f", cX)); LOG.info(String.format("Mean Y: %.2f", cY)); LOG.info(String.format("Mean Z: %.2f", cZ)); /* Calculate the distance from the centroid for each point. */ Double[] distances = new Double[points.length]; Double[] distancesAdjusted = new Double[points.length]; double maxD = Double.NEGATIVE_INFINITY; double maxDAdjusted = Double.NEGATIVE_INFINITY; for (int i = 0; i < points.length; i++) { Coord3d c = points[i]; double d = Math.sqrt(Math.pow(cX - c.x, 2) + Math.pow(cY - c.y, 2) + Math.pow(cZ - c.z, 2)); distances[i] = d; maxD = Math.max(maxD, d); /* Adjust distance to account for angle as well. Diagonals should be * penalised more. */ double multiplier = 1e-5; double angleXY = Math.atan2(Math.abs(c.y - centroid.y), Math.abs(c.x - centroid.x)); double angleXZ = Math.atan2(Math.abs(c.z - centroid.z), Math.abs(c.x - centroid.x)); distancesAdjusted[i] = d * Math.abs(Math.sin(angleXY * 2)) * // Math.abs( Math.sin(angleXZ*2) ) * multiplier; maxDAdjusted = Math.max(maxDAdjusted, distancesAdjusted[i]); } /* Set the colour for each point, based on the distances from the * data centroid. */ ColorMapRainbow map = new ColorMapRainbow(); Color[] colors = new Color[points.length]; for (int i = 0; i < points.length; i++) { colors[i] = map.getColor(0, 0, distancesAdjusted[i], 0, maxDAdjusted); } /* Make rainbow colors. */ Scatter scatter = new Scatter(points, colors, 4f); chart = AWTChartComponentFactory.chart(Quality.Advanced, "newt"); Polygon polygon1 = new Polygon(); polygon1.add(new Point(new Coord3d(-500, -500, 1000))); polygon1.add(new Point(new Coord3d(-500, 500, 1000))); polygon1.add(new Point(new Coord3d(500, 500, 1000))); polygon1.add(new Point(new Coord3d(500, -500, 1000))); polygon1.setColor(new Color(0f, 1f, 0f, 0.5f)); polygon1.setFaceDisplayed(true); Polygon polygon2 = new Polygon(); polygon2.add(new Point(new Coord3d(-500, -500, 800))); polygon2.add(new Point(new Coord3d(-500, 500, 800))); polygon2.add(new Point(new Coord3d(500, 500, 800))); polygon2.add(new Point(new Coord3d(500, -500, 800))); polygon2.setColor(new Color(1f, 0f, 0f, 0.5f)); polygon2.setFaceDisplayed(true); // chart.getScene().add(polygon1); // chart.getScene().add(polygon2); chart.getScene().add(scatter); }
public static Chart chart(String toolkit) { AWTChartComponentFactory f = new AWTChartComponentFactory(); return f.newChart(Chart.DEFAULT_QUALITY, toolkit); }
public static Chart chart(Quality quality, String toolkit) { AWTChartComponentFactory f = new AWTChartComponentFactory(); return f.newChart(quality, toolkit); }
public static Chart chart(Quality quality) { AWTChartComponentFactory f = new AWTChartComponentFactory(); return f.newChart(quality, Toolkit.newt); }