Friday, June 16, 2017

Using a quad to emulate an arc, solving for C.

Basic geometry allows one to solve for the best solution to use a value of C to make a bezier curve close to an arc. The naive solution using Geometry is


This is the solution to the question of we have anchor points on the curve and the curve touches the circle at the center, what value of C for a control point on the quadrant curve (0,1),(C,C),(1,0). Gives us the best fit to the curve.

However Mortenson points out that we are better if we minimize the error rather than allow all the error to be on one side of the circle.





This issue allows a few more percent with the Cubic Bezier form. But, it's more important if we're using one fewer control points. The same is also true at one fewer yet. If we have a square, what square looks most similar to a circle.

The if the naive geometry solution is the same we get:

. Where the corners touch the circle but do not exceed it. The other way you could do it is to have them only touch at the corners and just make the curve larger than the circle.




And finally we have Mortensen's solution to it, by making the metric for closest be the average error across the entire graph.

Well, solving this for 1 control point means doing the same thing he did. Which isn't super-trivial because it means calculating min and max error and adjusting various things. So I wrote a program to do it.

Your C points in Quad Bezier curves are:

C= 0.92519820883625651516056680057654772234129017577799879993432335355559372311727101122467939843041708056568481020881580812152533756252840773920708961655740969447362217856208142868847332990974178763987890


Having the program I refigured it for Cubic:
0.55191502449351057074356272279256664233618039472430889733698053746758709885277817592685338345358001614300815257463095148547403466508799941938848910944812198495136713728128014911200347760723733292314480

Having a deviation in both directions of: ±0.00019607646987687817401874512914923 ....

Mortensen gave this as,
0.551915024494

Since we might well be using doubles I'd give it as:
0.5519150244935106

M0,1
C0.5519150244935106,1 1,0.5519150244935106 1,0
C1,-0.5519150244935106 0.5519150244935106,-1 0,-1
C-0.5519150244935106,-1 -1,-0.5519150244935106 -1,0
C-1,0.5519150244935106 -0.5519150244935106,1 0,1


And the c value for the quad bezier curve as:
0.9251982088362565


M0,1
Q0.9251982088362565 0.9251982088362565 1,0
Q0.9251982088362565 -0.9251982088362565 0,-1
Q-0.9251982088362565 -0.9251982088362565 -1,0
Q-0.9251982088362565 0.9251982088362565 0,1

This is much better than the more naive value: 0.91421356237 which is effectively unusable. While Mortensen's use for the cubic is great, it changes the quad naive to almost usable, generally not, but *almost* usable. The Mortensen-optimized value for quads is off by max 0.007767318 whereas the naive value is off by 0.010781424258 which is 28% better. Hm. That's the same value Mortensen got for the cubic.
Naive Quad: For comparison.

No comments: