/** * 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); }