List of usage examples for java.awt.geom Arc2D containsAngle
public boolean containsAngle(double angle)
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; int w = getSize().width; int h = getSize().height; Arc2D arc = new Arc2D.Double(0.0, 0.0, w, h, 0.0, 60.0, Arc2D.CHORD); System.out.println(arc.containsAngle(0.6)); g2.draw(arc);// w w w . j a v a2 s . c o m arc = new Arc2D.Float(0.0f, 0.0f, w, h, 80.0f, 110.0f, Arc2D.PIE); g2.fill(arc); arc = new Arc2D.Float(0.0f, 0.0f, w, h, 210.0f, 130.0f, Arc2D.OPEN); g2.draw(arc); }
From source file:GeometryUtilities.java
public static Vector<Point2D> getCrossings(Arc2D arc0, Point2D arc0Center, Arc2D arc1, Point2D arc1Center) { Vector<Point2D> ret = new Vector<Point2D>(); double distance = arc0Center.distance(arc1Center); double radius0Squared = arc0Center.distanceSq(arc0.getStartPoint()); double radius0 = sqrt(radius0Squared); double radius1Squared = arc1Center.distanceSq(arc1.getStartPoint()); double radius1 = sqrt(radius1Squared); if (distance > radius0 + radius1) { // There are no solutions because the circles are separate. } else if (distance < abs(radius0 - radius1)) { // There are no solutions because one circle is contained within the // other. } else if (distance == 0 && radius0 == radius1) { // There are an infinite number of solutions because the circles are // coincident. } else {//from www .j ava2 s . com // Calculate the first intersection double x0 = arc0Center.getX(), y0 = arc0Center.getY(); double x1 = arc1Center.getX(), y1 = arc1Center.getY(); double a = (radius0Squared - radius1Squared + distance * distance) / (2 * distance); double h = sqrt(radius0Squared - a * a); double x2 = x0 + a * (x1 - x0) / distance; double y2 = y0 + a * (y1 - y0) / distance; Point2D.Double intersection = new Point2D.Double(x2 + h * (y1 - y0) / distance, y2 - h * (x1 - x0) / distance); double angle0ToIntersection = toDegrees(atan2(-(intersection.y - y0), intersection.x - x0)); double angle1ToIntersection = toDegrees(atan2(-(intersection.y - y1), intersection.x - x1)); if (arc0.containsAngle(angle0ToIntersection) && arc1.containsAngle(angle1ToIntersection)) ret.add(intersection); // If the circles aren't tangential, calculate the second // intersection if (distance != radius0 + radius1) { intersection = new Point2D.Double(x2 - h * (y1 - y0) / distance, y2 + h * (x1 - x0) / distance); angle0ToIntersection = toDegrees(atan2(-(intersection.y - y0), intersection.x - x0)); angle1ToIntersection = toDegrees(atan2(-(intersection.y - y1), intersection.x - x1)); if (arc0.containsAngle(angle0ToIntersection) && arc1.containsAngle(angle1ToIntersection)) ret.add(intersection); } } return ret; }