Cubic.circularArc constructor
Implementation
factory Cubic.circularArc(
double centerX,
double centerY,
double x0,
double y0,
double x1,
double y1,
) {
final p0d = directionVector(x0 - centerX, y0 - centerY);
final p1d = directionVector(x1 - centerX, y1 - centerY);
final rotatedP0 = p0d.rotate90();
final rotatedP1 = p1d.rotate90();
final clockwise =
rotatedP0.dotProductWith(x1 - centerX, y1 - centerY) >= 0.0;
final cosa = p0d.dotProduct(p1d);
if (cosa > 0.999) /* p0 ~= p1 */ return .straightLine(x0, y0, x1, y1);
final k =
distance(x0 - centerX, y0 - centerY) *
4.0 /
3.0 *
(math.sqrt(2.0 * (1.0 - cosa)) - math.sqrt(1 - cosa * cosa)) /
(1 - cosa) *
(clockwise ? 1.0 : -1.0);
return .from(
x0,
y0,
x0 + rotatedP0.x * k,
y0 + rotatedP0.y * k,
x1 - rotatedP1.x * k,
y1 - rotatedP1.y * k,
x1,
y1,
);
}