List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:Main.java
/** * Serialises a <code>Point2D</code> object. * * @param p the point object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. *//*from w w w . j a va 2s . com*/ public static void writePoint2D(final Point2D p, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (p != null) { stream.writeBoolean(false); stream.writeDouble(p.getX()); stream.writeDouble(p.getY()); } else { stream.writeBoolean(true); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java
private static LinearGradientPaint getTranslatedLinearGradientPaint(LinearGradientPaint gradient, Point2D startPoint, Point2D endPoint, boolean vertical) { if (vertical) { return new LinearGradientPaint(0f, (float) startPoint.getY(), 0f, (float) endPoint.getY(), gradient.getFractions(), gradient.getColors()); } else {//from ww w. ja v a2s . c om return new LinearGradientPaint((float) startPoint.getX(), 0f, (float) endPoint.getX(), 0f, gradient.getFractions(), gradient.getColors()); } }
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 w ww .j a v a 2 s.com*/ 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: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();//from w w w . jav a 2s .c o m 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: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. j a va2s . co 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 w w w. j av a2 s. c o m 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:ch.epfl.leb.sass.models.emitters.internal.AbstractEmitter.java
/** * Returns a list of pixels within a certain radius from a point. * /*from www . ja v a 2 s . c om*/ * 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; }
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; }//w w w . j av a2 s . c o m return true; }
From source file:controller.VisLP.java
/** * @param points/*w w w.java2 s .co m*/ * Unordered list of points that can form a * convex polygon, but in the given order * does not necessarily form a convex * polygon if edges are drawn between the * points in the given order. * @return * An ordered list of points that when edges * are drawn in this order is guaranteed to * form a convex polygon. */ static Point2D[] convex(Point2D[] points) { /* * Sort the points first on x-value then * on y-value, both in ascending order. */ Arrays.sort(points, new Comparator<Point2D>() { @Override public int compare(Point2D o1, Point2D o2) { double s = o1.getX() - o2.getX(); if (s > 0) return 1; if (s < 0) return -1; s = o1.getY() - o2.getY(); if (s > 0) return 1; if (s < 0) return -1; return 0; } }); Point2D x_min = points[0]; Point2D x_max = points[points.length - 1]; ArrayList<Point2D> upper = new ArrayList<Point2D>(); ArrayList<Point2D> lower = new ArrayList<Point2D>(); upper.add(x_min); /* Find the slope of the line L connecting x_min and x_max */ double mx = x_max.getX() - x_min.getX(); double my = x_max.getY() - x_min.getY(); double m = my / mx; /* Intersection of y-axis */ double b = x_max.getY() - (m * x_max.getX()); /* Add points above/below L to upper/lower, respectively */ for (int i = 1; i < points.length - 1; i++) { Point2D p2d = points[i]; double y = p2d.getX() * m + b; if (p2d.getY() >= y) upper.add(p2d); else lower.add(p2d); } /* Sort the lower list in descending order */ lower.add(x_max); Collections.reverse(lower); upper.addAll(lower); return upper.toArray(new Point2D[0]); }
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 w ww . java2 s . 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); }