Fits a cubic to an arc on the unit circle using the following
constraints:
1) The endpoints and tangent directions at the endpoints must match
the arc.
2) The cubic must be symmetric (length(p1 - p0) == length(p3 - p2)).
3) The height of the cubic must match the height of the arc.
Using the above constraints, we arrive at the following formula for the
control length (c) (i.e., lengths of (p1 - p0) and (p3 - p2)):
d = x0*x1 + y0*y1
c = (sqrt(1 + d) * kM + kA) * rsqrt(1 - d)
(Where x0,y0,x1,y1 are the endpoints, kM = -4/3, and kA = 4/3 * sqrt(2).)
The sample also comes with a root finder that finds the max error value
of the curve, which ends up serving as a semi-formal proof that:
1) Max error always occurs at T=0.21132486540519, regardless of
endpoints.
2) Error is reduced by exactly 64x each time we halve the arc angle
Change-Id: I29ad60dda06743d79f71275c38ffdd97261159ac
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295303
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Mike Reed <reed@google.com>