20 std::vector<sortedPoint> &pts,
int pos)
24 int newp = (int)pts.size() - 1;
30 std::vector<SPoint3> &pts,
31 std::vector<double> &ts)
34 pts.reserve(spts.size());
36 ts.reserve(spts.size());
37 for(
int p = 0; p != -1; p = spts[p].next) {
38 pts.push_back(spts[p].p);
39 ts.push_back(spts[p].t);
50 double dt2 = std::max(0., std::max(-
dot(d, d0),
dot(d, d1)));
52 return (dt2 + dn2) / d.
normSq();
55 static void decasteljau(
double tol, std::vector<sortedPoint> &discrete,
int pos,
62 SPoint3 p012((p01 + p12) * 0.5);
63 double t012 = 0.5 * (t0 + t2);
65 decasteljau(tol, discrete, pos, p0, p01, p012, t0, t012);
66 decasteljau(tol, discrete, newpos, p012, p12, p2, t012, t2);
70 const SPoint3 &p2, std::vector<SPoint3> &pts,
71 std::vector<double> &ts)
73 std::vector<sortedPoint> discrete;
75 discrete.push_back(pnt1);
77 discrete.push_back(pnt2);
82 static void decasteljau(
double tol, std::vector<sortedPoint> &discrete,
int pos,
84 const SPoint3 &p3,
double t0,
double t3)
92 SPoint3 p012((p01 + p12) * 0.5);
93 SPoint3 p123((p12 + p23) * 0.5);
94 SPoint3 p0123((p012 + p123) * 0.5);
95 double t0123 = 0.5 * (t0 + t3);
97 decasteljau(tol, discrete, pos, p0, p01, p012, p0123, t0, t0123);
98 decasteljau(tol, discrete, newpos, p0123, p123, p23, p3, t0123, t3);
103 std::vector<SPoint3> &pts, std::vector<double> &ts)
105 std::vector<sortedPoint> discrete;
107 discrete.push_back(pnt1);
109 discrete.push_back(pnt2);
110 decasteljau(tol, discrete, 0, p0, p1, p2, p3, 0., 1);
114 static void decasteljau(
double tol, std::vector<sortedPoint> &discrete,
int pos,
115 const std::vector<SPoint3> &pts,
double t0,
double te)
117 int order = (int)pts.size() - 1;
119 for(
int i = 1; i < order; ++i)
121 if(dmax2 < tol * tol)
return;
122 std::vector<SPoint3> sub0(pts.size());
123 std::vector<SPoint3> sub1(pts);
124 for(
int l = 0; l < order + 1; ++l) {
126 for(
int i = 0; i < order - l; ++i) sub1[i] = (sub1[i] + sub1[i + 1]) * 0.5;
128 double tmid = 0.5 * (t0 + te);
131 decasteljau(tol, discrete, newpos, sub1, tmid, te);
134 void decasteljau(
double tol,
const std::vector<SPoint3> &controlPoints,
135 std::vector<SPoint3> &pts, std::vector<double> &ts)
137 std::vector<sortedPoint> discrete;
139 discrete.push_back(pnt1);
141 discrete.push_back(pnt2);
142 decasteljau(tol, discrete, 0, controlPoints, 0., 1);