List of usage examples for java.awt.geom Rectangle2D setFrameFromDiagonal
public void setFrameFromDiagonal(Point2D p1, Point2D p2)
From source file:ShapeTest.java
public Shape makeShape(Point2D[] p) { Rectangle2D s = new Rectangle2D.Double(); s.setFrameFromDiagonal(p[0], p[1]); return s;//from w w w . j a v a2s. c o m }
From source file:ShapeTest.java
public Shape makeShape(Point2D[] p) { double centerX = (p[0].getX() + p[1].getX()) / 2; double centerY = (p[0].getY() + p[1].getY()) / 2; double width = Math.abs(p[1].getX() - p[0].getX()); double height = Math.abs(p[1].getY() - p[0].getY()); double skewedStartAngle = Math .toDegrees(Math.atan2(-(p[2].getY() - centerY) * width, (p[2].getX() - centerX) * height)); double skewedEndAngle = Math .toDegrees(Math.atan2(-(p[3].getY() - centerY) * width, (p[3].getX() - centerX) * height)); double skewedAngleDifference = skewedEndAngle - skewedStartAngle; if (skewedStartAngle < 0) skewedStartAngle += 360;/* www . ja va 2 s. co m*/ if (skewedAngleDifference < 0) skewedAngleDifference += 360; Arc2D s = new Arc2D.Double(0, 0, 0, 0, skewedStartAngle, skewedAngleDifference, Arc2D.OPEN); s.setFrameFromDiagonal(p[0], p[1]); GeneralPath g = new GeneralPath(); g.append(s, false); Rectangle2D r = new Rectangle2D.Double(); r.setFrameFromDiagonal(p[0], p[1]); g.append(r, false); Point2D center = new Point2D.Double(centerX, centerY); g.append(new Line2D.Double(center, p[2]), false); g.append(new Line2D.Double(center, p[3]), false); return g; }
From source file:org.uva.itast.blended.omr.pages.PageImage.java
/** * @param templateRectPx//from w w w.ja va 2 s. co m * @return */ public Rectangle2D toMilimeters(Rectangle boxPx) { Point2D p1 = toMilimeters(boxPx.x, boxPx.y); Point2D p2 = toMilimeters((int) boxPx.getMaxX(), (int) boxPx.getMaxY()); Rectangle2D bbox = new Rectangle(); bbox.setFrameFromDiagonal(p1, p2); return bbox; }