List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:mulavito.gui.components.LayerViewer.java
public static void autoZoomViewer(VisualizationViewer<?, ?> vv, LayerViewer<?, ?> home, Directions direction) { if (vv == null || home == null) return;//w w w . j a v a2 s .c o m // reset transforms MutableTransformer layoutTrans = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(edu.uci.ics.jung.visualization.Layer.LAYOUT); layoutTrans.setToIdentity(); MutableTransformer viewTrans = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(edu.uci.ics.jung.visualization.Layer.VIEW); viewTrans.setToIdentity(); Dimension dim = vv.getSize(); Rectangle2D.Double graphBounds = home.getGraphBoundsCache(); CrossoverScalingControl scaler = new CrossoverScalingControl(); // Scale using crossover scaler, so vertices will not grow // larger than they are in original double factor = Double.POSITIVE_INFINITY; if (direction == Directions.HORIZONTAL || direction == Directions.BOTH) factor = dim.getWidth() / graphBounds.width; if (direction == Directions.VERTICAL || direction == Directions.BOTH || Double.isInfinite(factor)) factor = Math.min(factor, dim.getHeight() / graphBounds.height); scaler.scale(vv, (float) factor, vv.getCenter()); // Translate center of graph to center of vv. Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); double dx = (lvc.getX() - graphBounds.getCenterX()); double dy = (lvc.getY() - graphBounds.getCenterY()); layoutTrans.translate(dx, dy); }
From source file:net.sf.mcf2pdf.mcfelements.util.ImageUtil.java
/** * Rotates the given buffered image by the given angle, and returns a newly * created image, containing the rotated image. * * @param img Image to rotate.//from ww w.j a v a2 s . c om * @param angle Angle, in radians, by which to rotate the image. * @param drawOffset Receives the offset which is required to draw the image, * relative to the original (0,0) corner, so that the center of the image is * still on the same position. * * @return A newly created image containing the rotated image. */ public static BufferedImage rotateImage(BufferedImage img, float angle, Point drawOffset) { int w = img.getWidth(); int h = img.getHeight(); AffineTransform tf = AffineTransform.getRotateInstance(angle, w / 2.0, h / 2.0); // get coordinates for all corners to determine real image size Point2D[] ptSrc = new Point2D[4]; ptSrc[0] = new Point(0, 0); ptSrc[1] = new Point(w, 0); ptSrc[2] = new Point(w, h); ptSrc[3] = new Point(0, h); Point2D[] ptTgt = new Point2D[4]; tf.transform(ptSrc, 0, ptTgt, 0, ptSrc.length); Rectangle rc = new Rectangle(0, 0, w, h); for (Point2D p : ptTgt) { if (p.getX() < rc.x) { rc.width += rc.x - p.getX(); rc.x = (int) p.getX(); } if (p.getY() < rc.y) { rc.height += rc.y - p.getY(); rc.y = (int) p.getY(); } if (p.getX() > rc.x + rc.width) rc.width = (int) (p.getX() - rc.x); if (p.getY() > rc.y + rc.height) rc.height = (int) (p.getY() - rc.y); } BufferedImage imgTgt = new BufferedImage(rc.width, rc.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgTgt.createGraphics(); // create a NEW rotation transformation around new center tf = AffineTransform.getRotateInstance(angle, rc.getWidth() / 2, rc.getHeight() / 2); g2d.setTransform(tf); g2d.drawImage(img, -rc.x, -rc.y, null); g2d.dispose(); drawOffset.x += rc.x; drawOffset.y += rc.y; return imgTgt; }
From source file:com.endlessloopsoftware.ego.client.graph.GraphData.java
public static void writeCoordinates(File dataFile) throws IOException { VisualizationViewer<Vertex, Edge> vv = GraphRenderer.getVv(); Layout<Vertex, Edge> layout = vv.getGraphLayout(); Graph g = layout.getGraph();// w w w .j a v a 2 s. c om FileWriter fw = new FileWriter(dataFile); @SuppressWarnings("unchecked") Collection<Vertex> verts = g.getVertices(); for (Vertex v : verts) { String nodeLabel = GraphRenderer.getGraphSettings().getNodeLabel(v); Point2D pt = layout.transform(v); String line = ("\"" + nodeLabel + "\"," + pt.getX() + "," + pt.getY() + "\n"); System.out.print(line); fw.write(line); } fw.close(); }
From source file:de.bund.bfr.jung.JungUtils.java
static Line2D getLineInMiddle(Shape edgeShape) { GeneralPath path = new GeneralPath(edgeShape); float[] seg = new float[6]; List<Point2D> points = new ArrayList<>(); for (PathIterator i = path.getPathIterator(null, 1); !i.isDone(); i.next()) { i.currentSegment(seg);/*from ww w .java 2 s . co m*/ points.add(new Point2D.Float(seg[0], seg[1])); } Point2D first = points.get(0); Point2D last = points.get(points.size() - 1); if (first.equals(last)) { Point2D minP = points.stream().min((p1, p2) -> Double.compare(p1.getY(), p2.getY())).get(); return new Line2D.Float(minP, new Point2D.Float((float) (minP.getX() + 1.0), (float) minP.getY())); } else { for (int i = 0; i < points.size() - 1; i++) { Point2D p1 = points.get(i); Point2D p2 = points.get(i + 1); if (p2.distance(last) < p2.distance(first)) { Line2D ortho = getOrthogonal(new Line2D.Float(first, last)); Point2D pp1 = getIntersection(new Line2D.Float(p1, p2), ortho); Point2D pp2 = new Point2D.Float((float) (pp1.getX() + last.getX() - first.getX()), (float) (pp1.getY() + last.getY() - first.getY())); return new Line2D.Float(pp1, pp2); } } return null; } }
From source file:org.jax.bham.util.JFreeChartUtil.java
/** * Convert from a Java2D point to a graph point * @param java2DPoint/* w w w.j av a 2 s . com*/ * the java 2D point to convert * @param chartPanel * the chart panel to convert * @return * the point */ public static Point2D java2DPointToGraphPoint(Point2D java2DPoint, ChartPanel chartPanel) { JFreeChart chart = chartPanel.getChart(); ChartRenderingInfo info = chartPanel.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); XYPlot xyPlot = chart.getXYPlot(); double graphX = xyPlot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, xyPlot.getDomainAxisEdge()); double graphY = xyPlot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, xyPlot.getRangeAxisEdge()); return new Point2D.Double(graphX, graphY); }
From source file:controller.VisLP.java
private static void scopeArea(CCSystem cs, Point2D[] points, boolean origo) { // No feasible points. Don't do anything. if (points.length == 0) return;// ww w. java 2 s .c o m if (points.length == 1) origo = true; double loX = origo ? 0 : Double.MAX_VALUE; double hiX = Double.MIN_VALUE; double loY = origo ? 0 : Double.MAX_VALUE; double hiY = Double.MIN_VALUE; for (Point2D p : points) { double x = p.getX(); double y = p.getY(); if (x < loX) loX = x; if (x > hiX) hiX = x; if (y < loY) loY = y; if (y > hiY) hiY = y; } if (loX == hiX) hiX = loX + 0.001; if (loY == hiY) hiY = loY + 0.001; double distX = hiX - loX; double distY = hiY - loY; cs.move(loX - distX * 0.1, hiX + distX * 0.1, loY - distY * 0.1, hiY + distY * 0.1); }
From source file:de.bund.bfr.jung.JungUtils.java
static <V, E> Shape getTransformedEdgeShape(RenderContext<V, E> rc, Layout<V, E> layout, E e) { Graph<V, E> graph = layout.getGraph(); edu.uci.ics.jung.graph.util.Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst();/*from ww w .j a v a 2s.com*/ V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(graph, e)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v2))) { return null; } Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); Shape edgeShape = rc.getEdgeShapeTransformer().transform(Context.getInstance(graph, e)); AffineTransform edgeShapeTransform = AffineTransform.getTranslateInstance(x1, y1); if (v1.equals(v2)) { Rectangle2D bounds = rc.getVertexShapeTransformer().transform(v1).getBounds2D(); edgeShapeTransform.scale(bounds.getWidth(), bounds.getHeight()); edgeShapeTransform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; edgeShapeTransform.rotate(Math.atan2(dy, dx)); edgeShapeTransform.scale(Math.sqrt(dx * dx + dy * dy), 1.0); } return edgeShapeTransform.createTransformedShape(edgeShape); }
From source file:controller.VisLP.java
private static boolean feasible(Point2D p2d, FieldMatrix<BigFraction> N, FieldVector<BigFraction> b) { double x = p2d.getX(); double y = p2d.getY(); for (int j = 0; j < N.getRowDimension(); j++) { float nx = N.getEntry(j, 0).floatValue(); float ny = N.getEntry(j, 1).floatValue(); float val = (float) (nx * x + ny * y); if (val > b.getEntry(j).floatValue()) return false; }/*from w ww. ja va 2s. c o m*/ return true; }
From source file:org.jcurl.demo.tactics.sg.BroomPromptScenario.java
/** adjust position + rotation */ private static void syncBroomM2V(final Point2D b, final Affine scene) { if (b == null) return;/*from www . j ava 2s . co m*/ final AffineTransform t = scene.getAffine(); t.setToIdentity(); t.translate(b.getX(), b.getY()); MathVec.rotate(t, b.getX(), b.getY() - IceSize.FAR_HACK_2_TEE); MathVec.rotate(t, 0, 1); scene.setAffine(t); }
From source file:ch.epfl.leb.sass.models.emitters.internal.AbstractEmitter.java
/** * Returns a list of pixels within a certain radius from a point. * /* w w w . j a v a 2 s. co m*/ * This method locates all the pixels within a circular area surrounding a * given two-dimensional point whose center lies at (x, y). The coordinate * of a pixel is assumed to lie at the pixel's center, and a pixel is within * a given radius of another if the pixel's center lies within this circle. * * @param point * @param radius radius value [pixels] * @return list of Pixels with pre-calculated signatures */ public static final ArrayList<Pixel> getPixelsWithinRadius(Point2D point, double radius) { ArrayList<Pixel> result = new ArrayList<Pixel>(); // If radius is less than one, return the pixel containing the point if (radius < 1) { int x = (int) point.getX(); int y = (int) point.getY(); result.add(new Pixel(x, y, 0)); return result; } // Upper and lower bounds for the region. final int bot_x = (int) floor(point.getX() - radius); final int top_x = (int) ceil(point.getX() + radius); final int bot_y = (int) floor(point.getY() - radius); final int top_y = (int) ceil(point.getY() + radius); // Squared radius so we dont have to do the sqrt() final double radius2 = radius * radius; // Iterate over all pixels in the square defined by the bounds and // filter out those which are too far, otherwise generate signature and // add to list. for (int i = bot_x; i <= top_x; i++) { for (int j = bot_y; j <= top_y; j++) { if (point.distanceSq((double) i, (double) j) <= radius2) { result.add(new Pixel(i, j, 0)); } } } return result; }