public static Shape createStar(int arms, Point center, double rOuter, double rInner) { double angle = Math.PI / arms; GeneralPath path = new GeneralPath(); for (int i = 0; i < 2 * arms; i++) { double r = (i & 1) == 0 ? rOuter : rInner; Point2D.Double p = new Point2D.Double(center.x + Math.cos(i * angle) * r, center.y + Math.sin(i * angle) * r); if (i == 0) path.moveTo(p.getX(), p.getY()); else path.lineTo(p.getX(), p.getY()); } path.closePath(); return path; }
public Point2D checkMiddleContactForSpecificTriangle(Point2D center) { for (int i = 0; i < all.size() - 1; i++) { final Point2D.Double pt1 = all.get(i); final Point2D.Double pt2 = all.get(i + 1); final Point2D.Double middle = new Point2D.Double((pt1.getX() + pt2.getX()) / 2, (pt1.getY() + pt2.getY()) / 2); final double delta = middle.distance(center); if (delta < 1) { return all.get((i - 1) % all.size()); } } return null; }
public Point2D.Double calcPoint(Point2D.Double start, Point2D.Double vector, double distance){ double x = start.getX() + (distance * vector.x); double y = start.getY() + (distance * vector.y); return new Point2D.Double(x, y); }
private static void writeAgent(AgentSnapshotInfo agInfo, ByteBuffer out) { String id = agInfo.getId().toString(); ByteBufferUtils.putString(out, id); Point2D.Double point = OTFServerQuadTree.transform(new Coord(agInfo.getEasting(), agInfo.getNorthing())); out.putFloat((float) point.getX()); out.putFloat((float) point.getY()); out.putInt(agInfo.getAgentState().ordinal() ) ; out.putInt(agInfo.getUserDefined()); out.putFloat((float)agInfo.getColorValueBetweenZeroAndOne()); }
/** Draws text at the specified location, where (0,0) * is the upper left corner of the the plot frame and (1,1) is * the lower right corner. Uses the justification specified by setJustification(). */ public void addLabel(double x, double y, String label) { if (textLoc!=null && x==textLoc.getX() && y==textLoc.getY()) allPlotObjects.set(textIndex, new PlotObject(label, x, y, currentJustification, currentFont, currentColor, PlotObject.NORMALIZED_LABEL)); else { allPlotObjects.add(new PlotObject(label, x, y, currentJustification, currentFont, currentColor, PlotObject.NORMALIZED_LABEL)); textLoc = new Point2D.Double(x,y); textIndex = allPlotObjects.size()-1; } }
Point2D.Double p1, p2; //p1 and p2 inits // you don't use abs value and use the still point as the first one of the subtraction double deltaX = p2.getX() - p1.getX(); double deltaY = p2.getY() - p1.getY(); // now you know how much far they are double coeff = 0.5; //this coefficient can be tweaked to decice how much near the two points will be after the update.. 0.5 = 50% of the previous distance p1.setLocation(p1.getX() + coeff*deltaX, p1.getY() + coeff*deltaY);
/** * @return bounding box of page */ public Rectangle2D getBoundingBox() { Dimension2dDouble sz = getPageSize(); Point2D.Double offset = getPageOffset(); return new Rectangle2D.Double(-offset.getX(), -offset.getY(), sz.getWidth(), sz.getHeight()); } }
import java.awt.geom.Point2D; //Note: only import Point2D, not Point2D.Double public class Test { public static void main(String[] args) { Point2D.Double point = new Point2D.Double(1.5, 2.5); double x = point.getX(); //1.5 double y = point.getY(); //2.5 Double xx = point.getX(); //1.5 Double yy = point.getY(); //2.5 } }
(a.getCoordinate().y + b.getCoordinate().y) / 2); double deltaXA_B = a.getCoordinate().x - midPointA_B.getX(); double deltaYA_B = a.getCoordinate().y - midPointA_B.getY(); new Point2D.Double( (midPointA_B.getX() + 100 * deltaYA_B), (midPointA_B.getY() - 100 * deltaXA_B)), new Point2D.Double( (midPointA_B.getX() - 100 * deltaYA_B), (midPointA_B.getY() + 100 * deltaXA_B))); (a.getCoordinate().y + c.getCoordinate().y) / 2); double deltaXA_C = a.getCoordinate().x - midPointA_C.getX(); double deltaYA_C = a.getCoordinate().y - midPointA_C.getY(); new Point2D.Double( (midPointA_C.getX() + Math.pow(100, i) * deltaYA_C), (midPointA_C.getY() - Math.pow(100, i) * deltaXA_C)), new Point2D.Double( (midPointA_C.getX() - Math.pow(100, i) * deltaYA_C), (midPointA_C.getY() + Math.pow(100, i) * deltaXA_C))); intersection = bisectorA_B.intersectionPoint(bisectorA_C); i++;
private void drawStepBar( Graphics2D g, S series, ArrayList<Point2D.Double> path, ArrayList<Point2D.Double> returnPath) { Collections.reverse(returnPath); // The last point will be a duplicate of the first. // Pop it before adding all to the main path returnPath.remove(returnPath.size() - 1); path.addAll(returnPath); Path2D.Double drawPath = new Path2D.Double(); // Start draw path from first point, which can then be discarded Point2D.Double startPoint = path.remove(0); drawPath.moveTo(startPoint.getX(), startPoint.getY()); // Prepare complete fill path for (Point2D.Double currentPoint : path) { drawPath.lineTo(currentPoint.getX(), currentPoint.getY()); } drawStepBarFill(g, series, drawPath); // Remove the bottom portion and draw only the upper outline drawPath.reset(); drawPath.moveTo(startPoint.getX(), startPoint.getY()); List<Point2D.Double> linePath = path.subList(0, path.size() - returnPath.size() + 1); for (Point2D.Double currentPoint : linePath) { drawPath.lineTo(currentPoint.getX(), currentPoint.getY()); } drawStepBarLine(g, series, drawPath); }
public MyCurve getCubicCurve2D() { MyCurve result = new MyCurve(new CubicCurve2D.Double(start.getX(), start.getY(), start.getX(), start.getY(), end.getX(), end.getY(), end.getX(), end.getY())); if (result.intersects(forbiddenRect) || result.intersects(forbiddenCurves)) { final Set<Point2D.Double> all = new HashSet<Point2D.Double>(); for (Point2D.Double p1 : all) { for (Point2D.Double p2 : all) { final MyCurve me = new MyCurve(new CubicCurve2D.Double(start.getX(), start.getY(), p1.getX(), p1 .getY(), p2.getX(), p2.getY(), end.getX(), end.getY())); if (me.getLenght() < min && me.intersects(forbiddenRect) == false && me.intersects(forbiddenCurves) == false) {
public Worm moveFirstPoint(UTranslate move) { final double dx = move.getDx(); final double dy = move.getDy(); if (dx != 0 && dy != 0) { throw new IllegalArgumentException("move=" + move); } final Worm result = new Worm(); double x0 = this.points.get(0).getX(); double y0 = this.points.get(0).getY(); double x1 = this.points.get(1).getX(); double y1 = this.points.get(1).getY(); if (dx != 0 && x0 == x1) { x1 += dx; } if (dy != 0 && y0 == y1) { y1 += dy; } x0 += dx; y0 += dy; result.addPoint(x0, y0); result.addPoint(x1, y1); for (int i = 2; i < this.points.size(); i++) { result.addPoint(this.points.get(i)); } return result; }
public Worm moveLastPoint(UTranslate move) { final double dx = move.getDx(); final double dy = move.getDy(); if (dx != 0 && dy != 0) { throw new IllegalArgumentException("move=" + move); } final Worm result = new Worm(); double x8 = this.points.get(this.points.size() - 2).getX(); double y8 = this.points.get(this.points.size() - 2).getY(); double x9 = this.points.get(this.points.size() - 1).getX(); double y9 = this.points.get(this.points.size() - 1).getY(); if (dx != 0 && x8 == x9) { x8 += dx; } if (dy != 0 && y8 == y9) { y8 += dy; } x9 += dx; y9 += dy; for (int i = 0; i < this.points.size() - 2; i++) { result.addPoint(this.points.get(i)); } result.addPoint(x8, y8); result.addPoint(x9, y9); return result; }
public boolean doesHorizontalCross(Point2D.Double pt1, Point2D.Double pt2) { if (pt1.getY() != pt2.getY()) { throw new IllegalArgumentException(); } if (pt1.getX() == pt2.getX()) { throw new IllegalArgumentException(); } final double y = pt1.getY(); if (y < minY || y > maxY) { return false; } if (pt1.getX() < minX && pt2.getX() > maxX) { return true; } if (pt2.getX() < minX && pt1.getX() > maxX) { return true; } return false; }
/** * @return bounding box of page */ public Rectangle2D getBoundingBox() { Dimension2dDouble sz = getPageSize(); Point2D.Double offset = getPageOffset(); return new Rectangle2D.Double(-offset.getX(), -offset.getY(), sz.getWidth(), sz.getHeight()); } }
public UPolygon(List<Point2D.Double> points) { this((String) null); all.addAll(points); for (Point2D.Double pt : all) { manageMinMax(pt.getX(), pt.getY()); } }
private void showMatchedPart(int idx) { Point2D.Double coord = matchedPartCoordinates.get(idx); Dimension treeSize = tjp.getPreferredSize(); JScrollBar horizontal = scroller.getHorizontalScrollBar(); JScrollBar vertical = scroller.getVerticalScrollBar(); int horizontalLength = horizontal.getMaximum() - horizontal.getMinimum(); double x = Math.max(0, (coord.getX() / treeSize.getWidth() * horizontalLength - (scroller.getWidth() / 2.0))); int verticalLength = vertical.getMaximum() - vertical.getMinimum(); double y = Math.max(0, (coord.getY() / treeSize.getHeight() * verticalLength - (scroller.getHeight() / 2.0))); horizontal.setValue((int) x); vertical.setValue((int) y); }