| OLD | NEW |
| 1 /* | 1 /* |
| 2 http://stackoverflow.com/questions/2009160/how-do-i-convert-the-2-control-points
-of-a-cubic-curve-to-the-single-control-poi | 2 http://stackoverflow.com/questions/2009160/how-do-i-convert-the-2-control-points
-of-a-cubic-curve-to-the-single-control-poi |
| 3 */ | 3 */ |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 Let's call the control points of the cubic Q0..Q3 and the control points of the
quadratic P0..P2. | 6 Let's call the control points of the cubic Q0..Q3 and the control points of the
quadratic P0..P2. |
| 7 Then for degree elevation, the equations are: | 7 Then for degree elevation, the equations are: |
| 8 | 8 |
| 9 Q0 = P0 | 9 Q0 = P0 |
| 10 Q1 = 1/3 P0 + 2/3 P1 | 10 Q1 = 1/3 P0 + 2/3 P1 |
| 11 Q2 = 2/3 P1 + 1/3 P2 | 11 Q2 = 2/3 P1 + 1/3 P2 |
| 12 Q3 = P2 | 12 Q3 = P2 |
| 13 In your case you have Q0..Q3 and you're solving for P0..P2. There are two ways t
o compute P1 from | 13 In your case you have Q0..Q3 and you're solving for P0..P2. There are two ways t
o compute P1 from |
| 14 the equations above: | 14 the equations above: |
| 15 | 15 |
| 16 P1 = 3/2 Q1 - 1/2 Q0 | 16 P1 = 3/2 Q1 - 1/2 Q0 |
| 17 P1 = 3/2 Q2 - 1/2 Q3 | 17 P1 = 3/2 Q2 - 1/2 Q3 |
| 18 If this is a degree-elevated cubic, then both equations will give the same answe
r for P1. Since | 18 If this is a degree-elevated cubic, then both equations will give the same answe
r for P1. Since |
| 19 it's likely not, your best bet is to average them. So, | 19 it's likely not, your best bet is to average them. So, |
| 20 | 20 |
| 21 P1 = -1/4 Q0 + 3/4 Q1 + 3/4 Q2 - 1/4 Q3 | 21 P1 = -1/4 Q0 + 3/4 Q1 + 3/4 Q2 - 1/4 Q3 |
| 22 | 22 |
| 23 | |
| 24 SkDCubic defined by: P1/2 - anchor points, C1/C2 control points | 23 SkDCubic defined by: P1/2 - anchor points, C1/C2 control points |
| 25 |x| is the euclidean norm of x | 24 |x| is the euclidean norm of x |
| 26 mid-point approx of cubic: a quad that shares the same anchors with the cubic an
d has the | 25 mid-point approx of cubic: a quad that shares the same anchors with the cubic an
d has the |
| 27 control point at C = (3·C2 - P2 + 3·C1 - P1)/4 | 26 control point at C = (3·C2 - P2 + 3·C1 - P1)/4 |
| 28 | 27 |
| 29 Algorithm | 28 Algorithm |
| 30 | 29 |
| 31 pick an absolute precision (prec) | 30 pick an absolute precision (prec) |
| 32 Compute the Tdiv as the root of (cubic) equation | 31 Compute the Tdiv as the root of (cubic) equation |
| 33 sqrt(3)/18 · |P2 - 3·C2 + 3·C1 - P1|/2 · Tdiv ^ 3 = prec | 32 sqrt(3)/18 · |P2 - 3·C2 + 3·C1 - P1|/2 · Tdiv ^ 3 = prec |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 for (int idx = 0; idx < last; ++idx) { | 177 for (int idx = 0; idx < last; ++idx) { |
| 179 part = subDivide(inflectT[idx], inflectT[idx + 1]); | 178 part = subDivide(inflectT[idx], inflectT[idx + 1]); |
| 180 addTs(part, precision, inflectT[idx], inflectT[idx + 1], ts); | 179 addTs(part, precision, inflectT[idx], inflectT[idx + 1], ts); |
| 181 } | 180 } |
| 182 part = subDivide(inflectT[last], 1); | 181 part = subDivide(inflectT[last], 1); |
| 183 addTs(part, precision, inflectT[last], 1, ts); | 182 addTs(part, precision, inflectT[last], 1, ts); |
| 184 return; | 183 return; |
| 185 } | 184 } |
| 186 addTs(*this, precision, 0, 1, ts); | 185 addTs(*this, precision, 0, 1, ts); |
| 187 } | 186 } |
| OLD | NEW |