@Override public Canvas drawArc(float cx, float cy, float r, float startAngle, float arcAngle) { float left = cx - r; float top = cy - r; float right = cx + r; float bottom = cy + r; rectf.set(left, top, right, bottom); canvas.drawArc(rectf, -FloatMath.toDegrees(startAngle), -FloatMath.toDegrees(arcAngle), false, currentState().prepareStroke()); isDirty = true; return this; }
@Override public Canvas drawArc(float cx, float cy, float r, float startAngle, float arcAngle) { int top = (int) (cx - r); int left = (int) (cy - r); int diam = (int) (2*r); currentState().prepareStroke(g2d); g2d.drawArc(top, left, diam, diam, FloatMath.round(FloatMath.toDegrees(startAngle)), FloatMath.round(FloatMath.toDegrees(arcAngle))); isDirty = true; return this; }
@Override public Canvas drawArc(float cx, float cy, float r, float startAngle, float arcAngle) { int top = (int) (cx - r); int left = (int) (cy - r); int diam = (int) (2*r); currentState().prepareStroke(g2d); g2d.drawArc(top, left, diam, diam, FloatMath.round(FloatMath.toDegrees(startAngle)), FloatMath.round(FloatMath.toDegrees(arcAngle))); isDirty = true; return this; }
/** * Sets the starting angle and angular extent of this arc using two sets of coordinates. The * first set of coordinates is used to determine the angle of the starting point relative to * the arc's center. The second set of coordinates is used to determine the angle of the end * point relative to the arc's center. The arc will always be non-empty and extend * counterclockwise from the first point around to the second point. */ public void setAngles (float x1, float y1, float x2, float y2) { float cx = centerX(); float cy = centerY(); float a1 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx))); float a2 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx))); a2 -= a1; if (a2 <= 0f) { a2 += 360f; } setAngleStart(a1); setAngleExtent(a2); }
/** * Sets the starting angle and angular extent of this arc using two sets of coordinates. The * first set of coordinates is used to determine the angle of the starting point relative to * the arc's center. The second set of coordinates is used to determine the angle of the end * point relative to the arc's center. The arc will always be non-empty and extend * counterclockwise from the first point around to the second point. */ public void setAngles (float x1, float y1, float x2, float y2) { float cx = centerX(); float cy = centerY(); float a1 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx))); float a2 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx))); a2 -= a1; if (a2 <= 0f) { a2 += 360f; } setAngleStart(a1); setAngleExtent(a2); }
/** * Sets the starting angle of this arc to the angle defined by the supplied point relative to * the center of this arc. */ public void setAngleStart (XY point) { float angle = FloatMath.atan2(point.y() - centerY(), point.x() - centerX()); setAngleStart(normAngle(-FloatMath.toDegrees(angle))); }
/** * Sets the starting angle of this arc to the angle defined by the supplied point relative to * the center of this arc. */ public void setAngleStart (XY point) { float angle = FloatMath.atan2(point.y() - centerY(), point.x() - centerX()); setAngleStart(normAngle(-FloatMath.toDegrees(angle))); }
/** * Sets the location, size, angular extents, and closure type of this arc based on the * specified values. */ public void setArcByTangent (XY p1, XY p2, XY p3, float radius) { // use simple geometric calculations of arc center, radius and angles by tangents float a1 = -FloatMath.atan2(p1.y() - p2.y(), p1.x() - p2.x()); float a2 = -FloatMath.atan2(p3.y() - p2.y(), p3.x() - p2.x()); float am = (a1 + a2) / 2f; float ah = a1 - am; float d = radius / Math.abs(FloatMath.sin(ah)); float x = p2.x() + d * FloatMath.cos(am); float y = p2.y() - d * FloatMath.sin(am); ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah; a1 = normAngle(FloatMath.toDegrees(am - ah)); a2 = normAngle(FloatMath.toDegrees(am + ah)); float delta = a2 - a1; if (delta <= 0f) { delta += 360f; } setArcByCenter(x, y, radius, a1, delta, type); }
/** * Sets the location, size, angular extents, and closure type of this arc based on the * specified values. */ public void setArcByTangent (XY p1, XY p2, XY p3, float radius) { // use simple geometric calculations of arc center, radius and angles by tangents float a1 = -FloatMath.atan2(p1.y() - p2.y(), p1.x() - p2.x()); float a2 = -FloatMath.atan2(p3.y() - p2.y(), p3.x() - p2.x()); float am = (a1 + a2) / 2f; float ah = a1 - am; float d = radius / Math.abs(FloatMath.sin(ah)); float x = p2.x() + d * FloatMath.cos(am); float y = p2.y() - d * FloatMath.sin(am); ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah; a1 = normAngle(FloatMath.toDegrees(am - ah)); a2 = normAngle(FloatMath.toDegrees(am + ah)); float delta = a2 - a1; if (delta <= 0f) { delta += 360f; } setArcByCenter(x, y, radius, a1, delta, type); }
@Override // from RectangularShape public boolean contains (float px, float py) { // normalize point float nx = (px - x()) / width() - 0.5f; float ny = (py - y()) / height() - 0.5f; if ((nx * nx + ny * ny) > 0.25) { return false; } float extent = angleExtent(); float absExtent = Math.abs(extent); if (absExtent >= 360f) { return true; } boolean containsAngle = containsAngle(FloatMath.toDegrees(-FloatMath.atan2(ny, nx))); if (arcType() == PIE) { return containsAngle; } if (absExtent <= 180f && !containsAngle) { return false; } Line l = new Line(startPoint(), endPoint()); int ccw1 = l.relativeCCW(px, py); int ccw2 = l.relativeCCW(centerX(), centerY()); return ccw1 == 0 || ccw2 == 0 || ((ccw1 + ccw2) == 0 ^ absExtent > 180f); }
@Override // from RectangularShape public boolean contains (float px, float py) { // normalize point float nx = (px - x()) / width() - 0.5f; float ny = (py - y()) / height() - 0.5f; if ((nx * nx + ny * ny) > 0.25) { return false; } float extent = angleExtent(); float absExtent = Math.abs(extent); if (absExtent >= 360f) { return true; } boolean containsAngle = containsAngle(FloatMath.toDegrees(-FloatMath.atan2(ny, nx))); if (arcType() == PIE) { return containsAngle; } if (absExtent <= 180f && !containsAngle) { return false; } Line l = new Line(startPoint(), endPoint()); int ccw1 = l.relativeCCW(px, py); int ccw2 = l.relativeCCW(centerX(), centerY()); return ccw1 == 0 || ccw2 == 0 || ((ccw1 + ccw2) == 0 ^ absExtent > 180f); }