Java Code Examples for java.awt.geom.Point2D#Double
The following examples show how to use
java.awt.geom.Point2D#Double .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.x, 1.0e-8); Assert.assertEquals(48.135167894, center.y, 1.0e-8); }
Example 2
Source File: BranchLengthsAdjust.java From MesquiteCore with GNU Lesser General Public License v3.0 | 6 votes |
void stretchTouched(int node, int x, int y, String mod) { Point2D.Double newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y); originalX = newOnLine.getX(); originalY = newOnLine.getY(); lastBL = tree.getBranchLength(node); lastX = treeDisplay.getTreeDrawing().lineTipX[node]; lastY = treeDisplay.getTreeDrawing().lineTipY[node]; double ibX = treeDisplay.getTreeDrawing().lineBaseX[node]; double ibY = treeDisplay.getTreeDrawing().lineBaseY[node]; if (GraphicsUtil.useXORMode(null, false)){ Graphics g = treeDisplay.getGraphics(); g.setXORMode(Color.white); g.setColor(Color.red); GraphicsUtil.drawString(g,MesquiteDouble.toString(lastBL), lastX+10, lastY); drawLine(g,ibX, ibY, lastX, lastY); drawLine(g,ibX+1, ibY, lastX+1, lastY); drawLine(g,ibX+2, ibY, lastX+2, lastY); g.dispose(); } lineOn=true; }
Example 3
Source File: GraphicsTests.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static Dimension scaleForTransform(AffineTransform at, Dimension dim) { int w = dim.width; int h = dim.height; Point2D.Double ptd = new Point2D.Double(0, 0); at.transform(ptd, ptd); double ox = ptd.getX(); double oy = ptd.getY(); if (ox < 0 || ox > w || oy < 0 || oy > h) { throw new InternalError("origin outside destination"); } double scalex = scaleForPoint(at, ox, oy, w, h, w, h); double scaley = scalex; scalex = Math.min(scaleForPoint(at, ox, oy, w, 0, w, h), scalex); scaley = Math.min(scaleForPoint(at, ox, oy, 0, h, w, h), scaley); if (scalex < 0 || scaley < 0) { throw new InternalError("could not fit dims to transform"); } return new Dimension((int) Math.floor(w * scalex), (int) Math.floor(h * scaley)); }
Example 4
Source File: XmasToStgConverter.java From workcraft with MIT License | 6 votes |
private void createReplicaReadArcsFromClockToCombinational(SignalStg rdy) throws InvalidConnectionException { double xt = 0.0; for (VisualSignalTransition t: rdy.getAllTransitions()) { xt += t.getRootSpaceX(); } xt /= rdy.getAllTransitions().size(); double xp = 0.0; double yp = 0.0; for (VisualPlace p: rdy.getAllPlaces()) { xp += p.getRootSpaceX(); yp += p.getRootSpaceY(); } xp /= rdy.getAllPlaces().size(); yp /= rdy.getAllPlaces().size(); Point2D clk0Pos = new Point2D.Double(xt + (xt - xp) / 2.0, yp); createReplicaReadArcs(clockStg.zero, rdy.getAllTransitions(), clk0Pos); }
Example 5
Source File: DiscretizedLocationOperator.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
private Set<Point2D> makeLocationList() { Set<Point2D> uniquePoints = new HashSet<Point2D>(); for (int i = 0; i < treeModel.getExternalNodeCount(); i++) { NodeRef node = treeModel.getExternalNode(i); double[] leafTrait = treeModel.getMultivariateNodeTrait(node, traitName); Point2D.Double point = new Point2D.Double(leafTrait[0], leafTrait[1]); if (!uniquePoints.contains(point)) { uniquePoints.add(point); savedPt = point; } } return uniquePoints; }
Example 6
Source File: SVGEmitter.java From maze-harvester with GNU General Public License v3.0 | 5 votes |
void computeBounds(Rectangle2D bbMazeCoords) { // Scale the bounding box up to add borders. Rectangle2D scaledBBox = bbMazeCoords; // Rotate the paper if the maze doesn't have the same aspect ratio. boolean paperIsTall = paperSizePixels.getX() < paperSizePixels.getY(); boolean mazeIsTall = scaledBBox.getWidth() < scaledBBox.getHeight(); if (paperIsTall != mazeIsTall) { this.paperSizePixels = new Point2D.Double(paperSizePixels.getY(), paperSizePixels.getX()); } // Account for the margins. double marginPixels = paperOptions.getMarginInches() * pixelsPerInch; Point2D availablePaperPixels = new Point2D.Double( paperSizePixels.getX() - marginPixels, paperSizePixels.getY() - marginPixels); scalePixelsPerRoom = Math.min( availablePaperPixels.getX() / scaledBBox.getWidth(), availablePaperPixels.getY() / scaledBBox.getHeight()); double marginRooms = marginPixels / scalePixelsPerRoom; Point2D paperRooms = new Point2D.Double( paperSizePixels.getX() / scalePixelsPerRoom, paperSizePixels.getY() / scalePixelsPerRoom); pageOffsetRooms = new Point2D.Double( scaledBBox.getX() - 0.5*(paperRooms.getX()-scaledBBox.getWidth()), scaledBBox.getY() - 0.5*(paperRooms.getY()-scaledBBox.getHeight())); }
Example 7
Source File: Point2DSerializationWrapper.java From pumpernickel with MIT License | 5 votes |
@Override public Point2D create() { Point2D p = (Point2D) map.get(KEY_SERIALIZABLE); if (p != null) return p; double x = ((Number) map.get(KEY_X)).doubleValue(); double y = ((Number) map.get(KEY_Y)).doubleValue(); return new Point2D.Double(x, y); }
Example 8
Source File: ScreenshotComponent.java From netbeans with Apache License 2.0 | 5 votes |
/** Computes the current image point, that is in the center in the current view area. */ private Point2D.Double computeCenterPoint() { Point p = scrollPane.getViewport().getViewPosition(); Rectangle viewRect = scrollPane.getViewport().getViewRect(); p.x += viewRect.width/2; p.y += viewRect.height/2; return new Point2D.Double(p.x / scale, p.y / scale); }
Example 9
Source File: AbstractBufferedImageOp.java From Smack with Apache License 2.0 | 5 votes |
@Override public Point2D getPoint2D(Point2D srcPt, Point2D dstPt) { if (dstPt == null) dstPt = new Point2D.Double(); dstPt.setLocation(srcPt.getX(), srcPt.getY()); return dstPt; }
Example 10
Source File: GraphReference.java From workcraft with MIT License | 4 votes |
public Point2D.Double getPageCentre() { return pageCentre; }
Example 11
Source File: MultiStartDifferentiableMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
public Circle() { points = new ArrayList<Point2D.Double>(); }
Example 12
Source File: LayoutPathImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
public Point2D pathToPoint(double a, double o, boolean preceding) { Point2D.Double pt = new Point2D.Double(a, o); pathToPoint(pt, preceding, pt); return pt; }
Example 13
Source File: SplineControlPanel.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static Template createTemplate(double x1, double y1, double x2, double y2) { return new Template(new Point2D.Double(x1, y1), new Point2D.Double(x2, y2)); }
Example 14
Source File: MultipleSelectionTool.java From openAGV with Apache License 2.0 | 4 votes |
@Override // DelegationSelectionTool protected void handleDoubleClick(MouseEvent evt) { DrawingView v = getView(); Point pos = new Point(evt.getX(), evt.getY()); Handle handle = v.findHandle(pos); // Special case PathConnection: Ignore double click if (handle != null && !(handle instanceof BezierOutlineHandle)) { handle.trackDoubleClick(pos, evt.getModifiersEx()); } else { Point2D.Double p = viewToDrawing(pos); // Note: The search sequence used here, must be // consistent with the search sequence used by the // HandleTracker, the SelectAreaTracker and SelectionTool. // If possible, continue to work with the current selection Figure figure = null; if (isSelectBehindEnabled()) { for (Figure f : v.getSelectedFigures()) { if (f.contains(p)) { figure = f; break; } } } // If the point is not contained in the current selection, // search for a figure in the drawing. if (figure == null) { figure = v.findFigure(pos); } Figure outerFigure = figure; if (figure != null && figure.isSelectable()) { Tool figureTool = figure.getTool(p); if (figureTool == null) { figure = getDrawing().findFigureInside(p); if (figure != null) { figureTool = figure.getTool(p); } } if (figureTool != null) { setTracker(figureTool); figureTool.mousePressed(evt); } else { if (outerFigure.handleMouseClick(p, evt, getView())) { v.clearSelection(); v.addToSelection(outerFigure); } else { v.clearSelection(); v.addToSelection(outerFigure); } } } } evt.consume(); }
Example 15
Source File: RadialGradientPaint.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Constructs a {@code RadialGradientPaint} with a default * {@code SRGB} color space. * The gradient circle of the {@code RadialGradientPaint} is defined * by the given bounding box. * <p> * This constructor is a more convenient way to express the * following (equivalent) code:<br> * * <pre> * double gw = gradientBounds.getWidth(); * double gh = gradientBounds.getHeight(); * double cx = gradientBounds.getCenterX(); * double cy = gradientBounds.getCenterY(); * Point2D center = new Point2D.Double(cx, cy); * * AffineTransform gradientTransform = new AffineTransform(); * gradientTransform.translate(cx, cy); * gradientTransform.scale(gw / 2, gh / 2); * gradientTransform.translate(-cx, -cy); * * RadialGradientPaint gp = * new RadialGradientPaint(center, 1.0f, center, * fractions, colors, * cycleMethod, * ColorSpaceType.SRGB, * gradientTransform); * </pre> * * @param gradientBounds the bounding box, in user space, of the circle * defining the outermost extent of the gradient * @param fractions numbers ranging from 0.0 to 1.0 specifying the * distribution of colors along the gradient * @param colors array of colors to use in the gradient. The first color * is used at the focus point, the last color around the * perimeter of the circle. * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT}, * or {@code REPEAT} * * @throws NullPointerException * if {@code gradientBounds} is null, * or {@code fractions} array is null, * or {@code colors} array is null, * or {@code cycleMethod} is null * @throws IllegalArgumentException * if {@code gradientBounds} is empty, * or {@code fractions.length != colors.length}, * or {@code colors} is less than 2 in size, * or a {@code fractions} value is less than 0.0 or greater than 1.0, * or the {@code fractions} are not provided in strictly increasing order */ public RadialGradientPaint(Rectangle2D gradientBounds, float[] fractions, Color[] colors, CycleMethod cycleMethod) { // gradient center/focal point is the center of the bounding box, // radius is set to 1.0, and then we set a scale transform // to achieve an elliptical gradient defined by the bounding box this(new Point2D.Double(gradientBounds.getCenterX(), gradientBounds.getCenterY()), 1.0f, new Point2D.Double(gradientBounds.getCenterX(), gradientBounds.getCenterY()), fractions, colors, cycleMethod, ColorSpaceType.SRGB, createGradientTransform(gradientBounds)); if (gradientBounds.isEmpty()) { throw new IllegalArgumentException("Gradient bounds must be " + "non-empty"); } }
Example 16
Source File: AbstractLinear.java From mars-sim with GNU General Public License v3.0 | 4 votes |
/** * Returns the image of the threshold indicator * @param WIDTH * @param HEIGHT * @return a buffered image of the threshold indicator */ protected BufferedImage create_THRESHOLD_Image(final int WIDTH, final int HEIGHT) { if (WIDTH <= 14 || HEIGHT <= 14) // 14 is needed otherwise the image size could be smaller than 1 { return UTIL.createImage(1, 1, Transparency.TRANSLUCENT); } final int IMAGE_WIDTH; final int IMAGE_HEIGHT; if (getOrientation() == Orientation.VERTICAL) { // Vertical orientation IMAGE_WIDTH = (int) (WIDTH * 0.0714285714); IMAGE_HEIGHT = (int) (IMAGE_WIDTH * 0.8); } else { // Horizontal orientation IMAGE_HEIGHT = (int) (HEIGHT * 0.0714285714); IMAGE_WIDTH = (int) (IMAGE_HEIGHT * 0.8); } final BufferedImage IMAGE = UTIL.createImage(IMAGE_WIDTH, IMAGE_HEIGHT, Transparency.TRANSLUCENT); final Graphics2D G2 = IMAGE.createGraphics(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); G2.translate(0, IMAGE_WIDTH * 0.005); final GeneralPath THRESHOLD = new GeneralPath(); THRESHOLD.setWindingRule(Path2D.WIND_EVEN_ODD); final Point2D THRESHOLD_START; final Point2D THRESHOLD_STOP; if (getOrientation() == Orientation.VERTICAL) { // Vertical orientation THRESHOLD.moveTo(IMAGE_WIDTH * 0.1, IMAGE_HEIGHT * 0.5); THRESHOLD.lineTo(IMAGE_WIDTH * 0.9, IMAGE_HEIGHT * 0.1); THRESHOLD.lineTo(IMAGE_WIDTH * 0.9, IMAGE_HEIGHT * 0.9); THRESHOLD.lineTo(IMAGE_WIDTH * 0.1, IMAGE_HEIGHT * 0.5); THRESHOLD.closePath(); THRESHOLD_START = new Point2D.Double(THRESHOLD.getBounds2D().getMinX(), 0); THRESHOLD_STOP = new Point2D.Double(THRESHOLD.getBounds2D().getMaxX(), 0); } else { // Horizontal orientation THRESHOLD.moveTo(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.9); THRESHOLD.lineTo(IMAGE_WIDTH * 1.0, IMAGE_HEIGHT * 0.1); THRESHOLD.lineTo(IMAGE_WIDTH * 0.1, IMAGE_HEIGHT * 0.1); THRESHOLD.lineTo(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.9); THRESHOLD.closePath(); THRESHOLD_START = new Point2D.Double(0, THRESHOLD.getBounds2D().getMaxY()); THRESHOLD_STOP = new Point2D.Double(0, THRESHOLD.getBounds2D().getMinY()); } final float[] THRESHOLD_FRACTIONS = { 0.0f, 0.3f, 0.59f, 1.0f }; final Color[] THRESHOLD_COLORS = { getThresholdColor().DARK, getThresholdColor().MEDIUM, getThresholdColor().MEDIUM, getThresholdColor().DARK }; final LinearGradientPaint THRESHOLD_GRADIENT = new LinearGradientPaint(THRESHOLD_START, THRESHOLD_STOP, THRESHOLD_FRACTIONS, THRESHOLD_COLORS); G2.setPaint(THRESHOLD_GRADIENT); G2.fill(THRESHOLD); G2.setColor(Color.WHITE); G2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); G2.draw(THRESHOLD); G2.dispose(); return IMAGE; }
Example 17
Source File: PiePlot.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Returns the center for the specified section. * Checks to see if the section is exploded and recalculates the * new center if so. * * @param state PiePlotState * @param key section key. * * @return The center for the specified section. * * @since 1.0.14 */ protected Point2D getArcCenter(PiePlotState state, Comparable key) { Point2D center = new Point2D.Double(state.getPieCenterX(), state .getPieCenterY()); double ep = getExplodePercent(key); double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = ep / mep; } if (ep != 0) { Rectangle2D pieArea = state.getPieArea(); Rectangle2D expPieArea = state.getExplodedPieArea(); double angle1, angle2; Number n = this.dataset.getValue(key); double value = n.doubleValue(); if (this.direction == Rotation.CLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 - value / state.getTotal() * 360.0; } else if (this.direction == Rotation.ANTICLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 + value / state.getTotal() * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2, Arc2D.OPEN); Point2D point1 = arc1.getEndPoint(); Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2, Arc2D.OPEN); Point2D point2 = arc2.getEndPoint(); double deltaX = (point1.getX() - point2.getX()) * ep; double deltaY = (point1.getY() - point2.getY()) * ep; center = new Point2D.Double(state.getPieCenterX() - deltaX, state.getPieCenterY() - deltaY); } return center; }
Example 18
Source File: ShapeUtilitiesViewer.java From sis with Apache License 2.0 | 4 votes |
/** * Assigns random values to the points. */ @SuppressWarnings("fallthrough") final void assignRandomPoints(final Method method) { input .reset(); output.reset(); fillInput = true; fillOutput = true; boolean horizontal = false; final int x = getX(); final int y = getY(); final int width = getWidth(); final int height = getHeight(); final int x1 = x + random.nextInt(width); final int y1 = y + random.nextInt(height); final int x2 = x + random.nextInt(width); final int y2 = y + random.nextInt(height); final int x3 = x + random.nextInt(width); final int y3 = y + random.nextInt(height); final int x4 = x + random.nextInt(width); final int y4 = y + random.nextInt(height); switch (method) { case INTERSECTION_POINT: { input.moveTo(x1, y1); input.lineTo(x2, y2); input.moveTo(x3, y3); input.lineTo(x4, y4); addPoint(output, ShapeUtilities.intersectionPoint(x1, y1, x2, y2, x3, y3, x4, y4)); out.printf(Locale.ENGLISH, "intersectionPoint(%d, %d, %d, %d, %d, %d, %d, %d)%n", x1, y1, x2, y2, x3, y3, x4, y4); break; } case NEAREAST_COLINEAR_POINT: { input.moveTo(x1, y1); input.lineTo(x2, y2); addPoint(input, x3, y3); addPoint(output, ShapeUtilities.nearestColinearPoint(x1, y1, x2, y2, x3, y3)); out.printf(Locale.ENGLISH, "nearestColinearPoint(%d, %d, %d, %d, %d, %d)%n", x1, y1, x2, y2, x3, y3); break; } case DISTANCED_COLINEAR_POINT: { final double distance = StrictMath.hypot(x4, y4); input.moveTo(x1, y1); input.lineTo(x2, y2); addPoint(input, x3, y3); addPoint(output, ShapeUtilities.colinearPoint(x1, y1, x2, y2, x3, y3, distance)); out.printf(Locale.ENGLISH, "colinearPoint(%d, %d, %d, %d, %d, %d, %g)%n", x1, y1, x2, y2, x3, y3, distance); break; } case FIT_PARABOL_HORIZONTAL: { horizontal = true; // Fall through } case FIT_PARABOL: { addPoint(input, x1, y1); addPoint(input, x2, y2); addPoint(input, x3, y3); output.append(ShapeUtilities.fitParabol(x1, y1, x2, y2, x3, y3, horizontal), false); out.printf(Locale.ENGLISH, "fitParabol(%d, %d, %d, %d, %d, %d, %b)%n", x1, y1, x2, y2, x3, y3, horizontal); fillOutput = false; break; } case BEZIER: { addPoint(input, x1, y1); addPoint(input, x2, y2); addPoint(input, x3, y3); final double α1 = (y4 - y1) / (double) (x4 - x1); // (x4, y4) used as a point for computing tangents. final double α2 = (y3 - y4) / (double) (x3 - x4); input.moveTo(x1, y1); input.lineTo(x4, y4); input.lineTo(x3, y3); output.append(ShapeUtilitiesExt.bezier(x1, y1, x2, y2, x3, y3, α1, α2, 1, 1), false); out.printf(Locale.ENGLISH, "fitCubicCurve(%d, %d, %d, %d, %d, %d, %g, %g)%n", x1, y1, x2, y2, x3, y3, α1, α2); fillOutput = false; fillInput = false; break; } case CIRCLE_CENTRE: { addPoint(input, x1, y1); addPoint(input, x2, y2); addPoint(input, x3, y3); final Point2D.Double center = ShapeUtilities.circleCentre(x1, y1, x2, y2, x3, y3); addPoint(output, center); final double radius = StrictMath.hypot(center.x - x1, center.y - y1); output.append(new Ellipse2D.Double(center.x - radius, center.y - radius, radius*2, radius*2), false); out.printf(Locale.ENGLISH, "circleCentre(%d, %d, %d, %d, %d, %d)%n", x1, y1, x2, y2, x3, y3); fillOutput = false; break; } } out.flush(); repaint(); }
Example 19
Source File: SpaceTime.java From beast-mcmc with GNU Lesser General Public License v2.1 | 3 votes |
public static void paintDot(SpaceTime s, double radius, AffineTransform transform, Graphics2D g2d) { Point2D pointRaw = new Point2D.Double(s.getX(0), s.getX(1)); Point2D pointT = new Point2D.Double(); transform.transform(pointRaw, pointT); Shape pointShape = new Ellipse2D.Double(pointT.getX() - radius, pointT.getY() - radius, 2.0 * radius, 2.0 * radius); g2d.fill(pointShape); }
Example 20
Source File: RadialGradientPaint.java From Java8CN with Apache License 2.0 | 2 votes |
/** * Returns a copy of the focus point of the radial gradient. * Note that if the focus point specified when the radial gradient * was constructed lies outside of the radius of the circle, this * method will still return the original focus point even though * the rendering may center the rings of color on a different * point that lies inside the radius. * * @return a {@code Point2D} object that is a copy of the focus point */ public Point2D getFocusPoint() { return new Point2D.Double(focus.getX(), focus.getY()); }