OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2012 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 #include "QuadraticLineSegments.h" | |
8 | |
9 // http://cagd.cs.byu.edu/~557/text/cagd.pdf 2.7 | |
10 // A hodograph is the first derivative curve | |
11 void hodograph(const Quadratic& quad, _Line& hodo) { | |
12 hodo[0].x = 2 * (quad[1].x - quad[0].x); | |
13 hodo[0].y = 2 * (quad[1].y - quad[0].y); | |
14 hodo[1].x = 2 * (quad[2].x - quad[1].x); | |
15 hodo[1].y = 2 * (quad[2].y - quad[1].y); | |
16 } | |
17 | |
18 // A 2nd hodograph is the second derivative curve | |
19 void secondHodograph(const Quadratic& quad, _Point& hodo2) { | |
20 _Line hodo; | |
21 hodograph(quad, hodo); | |
22 hodo2.x = hodo[1].x - hodo[0].x; | |
23 hodo2.y = hodo[1].y - hodo[0].y; | |
24 } | |
25 | |
26 // The number of line segments required to approximate the quad | |
27 // see http://cagd.cs.byu.edu/~557/text/cagd.pdf 10.6 | |
28 double subDivisions(const Quadratic& quad) { | |
29 _Point hodo2; | |
30 secondHodograph(quad, hodo2); | |
31 double dist = sqrt(hodo2.x * hodo2.x + hodo2.y * hodo2.y); | |
32 double segments = sqrt(dist / (8 * FLT_EPSILON)); | |
33 return segments; | |
34 } | |
OLD | NEW |