List of usage examples for java.awt.geom Point2D.Double Point2D.Double
public Double(double x, double y)
From source file:graticules2wld.Main.java
/** * @param args/*from ww w. j ava 2 s . c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { /* parse the command line arguments */ // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption("x", "originx", true, "x component of projected coordinates of upper left pixel"); options.addOption("y", "originy", true, "y component of projected coordinates of upper left pixel"); options.addOption("u", "tometers", true, "multiplication factor to get source units into meters"); options.addOption("h", "help", false, "prints this usage page"); options.addOption("d", "debug", false, "prints debugging information to stdout"); double originNorthing = 0; double originEasting = 0; String inputFileName = null; String outputFileName = null; try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printUsage(0); // print usage then exit using a non error exit status if (line.hasOption("debug")) debug = true; // these arguments are required if (!line.hasOption("originy") || !line.hasOption("originx")) printUsage(1); originNorthing = Double.parseDouble(line.getOptionValue("originy")); originEasting = Double.parseDouble(line.getOptionValue("originx")); if (line.hasOption("tometers")) unitsToMeters = Double.parseDouble(line.getOptionValue("tometers")); // two args should be left. the input csv file name and the output wld file name. String[] iofiles = line.getArgs(); if (iofiles.length < 2) { printUsage(1); } inputFileName = iofiles[0]; outputFileName = iofiles[1]; } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } // try to open the input file for reading and the output file for writing File graticulesCsvFile; BufferedReader csvReader = null; File wldFile; BufferedWriter wldWriter = null; try { graticulesCsvFile = new File(inputFileName); csvReader = new BufferedReader(new FileReader(graticulesCsvFile)); } catch (IOException exp) { System.err.println("Could not open input file for reading: " + inputFileName); System.exit(1); } try { wldFile = new File(outputFileName); wldWriter = new BufferedWriter(new FileWriter(wldFile)); } catch (IOException exp) { System.err.println("Could not open output file for writing: " + outputFileName); System.exit(1); } // list of lon graticules and lat graticules ArrayList<Graticule> lonGrats = new ArrayList<Graticule>(); ArrayList<Graticule> latGrats = new ArrayList<Graticule>(); // read the source CSV and convert its information into the two ArrayList<Graticule> data structures readCSV(csvReader, lonGrats, latGrats); // we now need to start finding the world file paramaters DescriptiveStatistics stats = new DescriptiveStatistics(); // find theta and phi for (Graticule g : latGrats) { stats.addValue(g.angle()); } double theta = stats.getMean(); // we use the mean of the lat angles as theta if (debug) System.out.println("theta range = " + Math.toDegrees(stats.getMax() - stats.getMin())); stats.clear(); for (Graticule g : lonGrats) { stats.addValue(g.angle()); } double phi = stats.getMean(); // ... and the mean of the lon angles for phi if (debug) System.out.println("phi range = " + Math.toDegrees(stats.getMax() - stats.getMin())); stats.clear(); // print these if in debug mode if (debug) { System.out.println("theta = " + Math.toDegrees(theta) + "deg"); System.out.println("phi = " + Math.toDegrees(phi) + "deg"); } // find x and y (distance beteen pixels in map units) Collections.sort(latGrats); Collections.sort(lonGrats); int prevMapValue = 0; //fixme: how to stop warning about not being initilised? Line2D prevGratPixelSys = new Line2D.Double(); boolean first = true; for (Graticule g : latGrats) { if (!first) { int deltaMapValue = Math.abs(g.realValue() - prevMapValue); double deltaPixelValue = (g.l.ptLineDist(prevGratPixelSys.getP1()) + (g.l.ptLineDist(prevGratPixelSys.getP2()))) / 2; double delta = deltaMapValue / deltaPixelValue; stats.addValue(delta); } else { first = false; prevMapValue = g.realValue(); prevGratPixelSys = (Line2D) g.l.clone(); } } double y = stats.getMean(); if (debug) System.out.println("y range = " + (stats.getMax() - stats.getMin())); stats.clear(); first = true; for (Graticule g : lonGrats) { if (!first) { int deltaMapValue = g.realValue() - prevMapValue; double deltaPixelValue = (g.l.ptLineDist(prevGratPixelSys.getP1()) + (g.l.ptLineDist(prevGratPixelSys.getP2()))) / 2; double delta = deltaMapValue / deltaPixelValue; stats.addValue(delta); } else { first = false; prevMapValue = g.realValue(); prevGratPixelSys = (Line2D) g.l.clone(); } } double x = stats.getMean(); if (debug) System.out.println("x range = " + (stats.getMax() - stats.getMin())); stats.clear(); if (debug) { System.out.println("x = " + x); System.out.println("y = " + y); } SimpleRegression regression = new SimpleRegression(); // C, F are translation terms: x, y map coordinates of the center of the upper-left pixel for (Graticule g : latGrats) { // find perp dist to pixel space 0,0 Double perpPixelDist = g.l.ptLineDist(new Point2D.Double(0, 0)); // find the map space distance from this graticule to the center of the 0,0 pixel Double perpMapDist = perpPixelDist * y; // perpMapDist / perpPixelDist = y regression.addData(perpMapDist, g.realValue()); } double F = regression.getIntercept(); regression.clear(); for (Graticule g : lonGrats) { // find perp dist to pixel space 0,0 Double perpPixelDist = g.l.ptLineDist(new Point2D.Double(0, 0)); // find the map space distance from this graticule to the center of the 0,0 pixel Double perpMapDist = perpPixelDist * x; // perpMapDist / perpPixelDist = x regression.addData(perpMapDist, g.realValue()); } double C = regression.getIntercept(); regression.clear(); if (debug) { System.out.println("Upper Left pixel has coordinates " + C + ", " + F); } // convert to meters C *= unitsToMeters; F *= unitsToMeters; // C,F store the projected (in map units) coordinates of the upper left pixel. // originNorthing,originEasting is the offset we need to apply to 0,0 to push the offsets into our global coordinate system C = originEasting + C; F = originNorthing + F; // calculate the affine transformation matrix elements double D = -1 * x * unitsToMeters * Math.sin(theta); double A = x * unitsToMeters * Math.cos(theta); double B = y * unitsToMeters * Math.sin(phi); // if should be negative, it'll formed by negative sin double E = -1 * y * unitsToMeters * Math.cos(phi); /* * Line 1: A: pixel size in the x-direction in map units/pixel * Line 2: D: rotation about y-axis * Line 3: B: rotation about x-axis * Line 4: E: pixel size in the y-direction in map units, almost always negative[3] * Line 5: C: x-coordinate of the center of the upper left pixel * Line 6: F: y-coordinate of the center of the upper left pixel */ if (debug) { System.out.println("A = " + A); System.out.println("D = " + D); System.out.println("B = " + B); System.out.println("E = " + E); System.out.println("C = " + C); System.out.println("F = " + F); // write the world file System.out.println(); System.out.println("World File:"); System.out.println(A); System.out.println(D); System.out.println(B); System.out.println(E); System.out.println(C); System.out.println(F); } // write to the .wld file wldWriter.write(A + "\n"); wldWriter.write(D + "\n"); wldWriter.write(B + "\n"); wldWriter.write(E + "\n"); wldWriter.write(C + "\n"); wldWriter.write(F + "\n"); wldWriter.close(); }
From source file:joshua.ui.alignment_visualizer.WordAlignmentLayout.java
private static Transformer<Word, Point2D> calculateInitializer(Graph<Word, Integer> g, double height, double spacing) { HashMap<Word, Point2D> map = new HashMap<Word, Point2D>(); for (Word w : g.getVertices()) { double x, y; if (w.isSource()) y = 0.0;//from w w w. j ava2 s .c o m else y = height; x = spacing * w.position(); map.put(w, new Point2D.Double(x, y)); } return TransformerUtils.mapTransformer(map); }
From source file:GraphicsUtil.java
public static Point2D getPoint(RectangularShape bounds, Align align) { double x = 0.0; double y = 0.0; switch (align) { case North://from ww w . j a v a 2 s.co m x = bounds.getCenterX(); y = bounds.getMinY(); break; case NorthEast: x = bounds.getMaxX(); y = bounds.getMinY(); break; case East: x = bounds.getMaxX(); y = bounds.getCenterY(); break; case SouthEast: x = bounds.getMaxX(); y = bounds.getMaxY(); break; case South: x = bounds.getCenterX(); y = bounds.getMaxY(); break; case SouthWest: x = bounds.getMinX(); y = bounds.getMaxY(); break; case West: x = bounds.getMinX(); y = bounds.getCenterY(); break; case NorthWest: x = bounds.getMinX(); y = bounds.getMinY(); break; case Center: x = bounds.getCenterX(); y = bounds.getCenterY(); break; } return new Point2D.Double(x, y); }
From source file:grafix.telas.MolduraAreaDados.java
private Point2D converterPontoNaMolduraParaPlot_EixoLinear(final Point2D pontoMoldura) { XYPlot plot = getPlot();// www .j av a 2 s . c o m ValueAxis vAxis = plot.getRangeAxis(); ValueAxis dAxis = plot.getDomainAxis(); double fracaoX = pontoMoldura.getX() / this.getWidth(); double fracaoY = 1 - (pontoMoldura.getY() / this.getHeight()); double dX = dAxis.getUpperBound() - dAxis.getLowerBound(); double dY = vAxis.getUpperBound() - vAxis.getLowerBound(); return new Point2D.Double(dAxis.getLowerBound() + dX * fracaoX, vAxis.getLowerBound() + dY * fracaoY); }
From source file:grafix.telas.MolduraAreaDados.java
private Point2D converterPontoNaMolduraParaPlot_EixoLog(final Point2D pontoMoldura) { XYPlot plot = getPlot();// ww w . ja v a 2 s .c om ValueAxis vAxis = plot.getRangeAxis(); ValueAxis dAxis = plot.getDomainAxis(); double fracaoX = pontoMoldura.getX() / this.getWidth(); double fracaoYlog = 1 - (pontoMoldura.getY() / this.getHeight()); double dX = dAxis.getUpperBound() - dAxis.getLowerBound(); double dYlog = Math.log10(vAxis.getUpperBound()) - Math.log10(vAxis.getLowerBound()); double ylog = Math.log10(vAxis.getLowerBound()) + fracaoYlog * dYlog; return new Point2D.Double(dAxis.getLowerBound() + dX * fracaoX, Math.pow(10, ylog)); }
From source file:grafix.telas.MolduraAreaDados.java
private Point2D converterPontoNoPlotParaMoldura_EixoLinear(final Point2D pontoPlot) { XYPlot plot = getPlot();// ww w .j ava 2s. com ValueAxis vAxis = plot.getRangeAxis(); ValueAxis dAxis = plot.getDomainAxis(); double dX = dAxis.getUpperBound() - dAxis.getLowerBound(); double dY = vAxis.getUpperBound() - vAxis.getLowerBound(); double proporcaoX = this.getWidth() / dX; double proporcaoY = this.getHeight() / dY; double fracaoX = pontoPlot.getX() - dAxis.getLowerBound(); double fracaoY = pontoPlot.getY() - vAxis.getLowerBound(); return new Point2D.Double(fracaoX * proporcaoX, this.getHeight() - (fracaoY * proporcaoY)); }
From source file:org.n52.oxf.render.sos.ProportionalCircleMapRenderer.java
/** * renders one frame of the animation./*from w w w. j av a 2s . co m*/ */ private Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures, ObservationSeriesCollection obsValues) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex]; // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); // draw time-string into map: g.setColor(Color.BLACK); g.drawString(currentTimePos.toString(), 20, 20); for (OXFFeature dotFeature : selectedFeatures) { // // draw the points into the image at the georeferenced position of the corresponding feature: // Point pRealWorld = (Point) dotFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); ObservedValueTuple tuple = obsValues.getTuple(dotFeature, currentTimePos); // if there wasn't a tuple for the current time position go backwards through the sortedTimeArray and take the most recent one: int j = currentTimeIndex - 1; while (tuple == null && j >= 0) { tuple = obsValues.getTuple(dotFeature, sortedTimeArray[j]); j--; } // if a tuple was found -> draw the dot: if (tuple != null) { int dotSize = computeDotSize((Double) tuple.getValue(0), (Double) obsValues.getMinimum(0), (Double) obsValues.getMaximum(0)); g.setColor(POINT_INNER_COLOR); g.fillOval(pScreen.x - (dotSize / 2), pScreen.y - (dotSize / 2), dotSize, dotSize); } // otherwise draw "no data available" else { g.setColor(Color.BLACK); // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } } return image; }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
/**<!====== drawItem ======================================================> Draws a 3D bar to represent one data item. <! Name Description> @param g2 the graphics device. @param state the renderer state. @param dataArea the area for plotting the data. @param plot the plot.//from w w w. ja v a2s .com @param domainAxis the domain axis. @param rangeAxis the range axis. @param dataset the dataset. @param row the row index (zero-based). @param column the column index (zero-based). @param pass the pass index. <!=======================================================================>*/ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } g2.setStroke(new BasicStroke(1)); double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof Color) { Color endColor = getFrontDark((Color) itemPaint); Color startColor = (Color) itemPaint; Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor, (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor); g2.setPaint(paint); } g2.fill(bar); double x0 = bar.getMinX(); // left double x1 = x0 + getXOffset(); // offset left double x2 = bar.getMaxX(); // right double x3 = x2 + getXOffset(); // offset right double y0 = bar.getMinY() - getYOffset(); // offset top double y1 = bar.getMinY(); // bar top double y2 = bar.getMaxY() - getYOffset(); // offset bottom double y3 = bar.getMaxY(); // bottom //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight()); Line2D.Double line = new Line2D.Double(x2, y1, x2, y3); g2.draw(line); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; g2.setPaint(itemPaint); // Draw the right side if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { Color startColor = getSideLight((Color) itemPaint); Color endColor = getSideDark((Color) itemPaint); Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3, endColor); g2.setPaint(paint); } g2.fill(bar3dRight); } // Draw the top bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); // bottom left bar3dTop.lineTo((float) x1, (float) y0); // top left bar3dTop.lineTo((float) x3, (float) y0); // top right bar3dTop.lineTo((float) x2, (float) y1); // bottom right bar3dTop.closePath(); if (itemPaint instanceof Color) { Color endColor = getTopDark((Color) itemPaint); Color startColor = getTopLight((Color) itemPaint); //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor); Point2D.Double topRight = new Point2D.Double(x3, y0); Point2D.Double bottomLeft = new Point2D.Double(x0, y1); //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2))); Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2))); Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor, (float) darkEnd.getX(), (float) darkEnd.getY(), endColor); g2.setPaint(paint); //drawMarker(topRight, g2, startColor); } g2.fill(bar3dTop); g2.setPaint(itemPaint); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:grafix.telas.MolduraAreaDados.java
private Point2D converterPontoNoPlotParaMoldura_EixoLog(final Point2D pontoPlot) { XYPlot plot = getPlot();/*from ww w . j a v a2 s. co m*/ ValueAxis vAxis = plot.getRangeAxis(); ValueAxis dAxis = plot.getDomainAxis(); double dX = dAxis.getUpperBound() - dAxis.getLowerBound(); double dYlog = Math.log10(vAxis.getUpperBound()) - Math.log10(vAxis.getLowerBound()); double proporcaoX = this.getWidth() / dX; double fracaoX = pontoPlot.getX() - dAxis.getLowerBound(); double fracaoYlog = Math.log10(pontoPlot.getY()) - Math.log10(vAxis.getLowerBound()); double coefYlog = fracaoYlog / dYlog; return new Point2D.Double(fracaoX * proporcaoX, this.getHeight() - (coefYlog * this.getHeight())); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java
public Point2D screenToDataCoords(Point2D p) { Rectangle2D data_area = theChartPanel.getScreenDataArea(); double x = thePlot.getDomainAxis().java2DToValue(p.getX(), data_area, thePlot.getDomainAxisEdge()); double y = thePlot.getRangeAxis().java2DToValue(p.getY(), data_area, thePlot.getRangeAxisEdge()); return new Point2D.Double(x, y); }