mirror of https://github.com/vitalif/openscad
Made Bezier code slightly more easy to read
parent
72ca3c849d
commit
c2cb2377f5
|
@ -95,24 +95,27 @@ void DrawingCallback::line_to(Vector2d to)
|
|||
pen = to;
|
||||
}
|
||||
|
||||
// Quadric Bezier curve
|
||||
void DrawingCallback::curve_to(Vector2d c1, Vector2d to)
|
||||
{
|
||||
for (unsigned long idx = 1;idx <= fn;idx++) {
|
||||
const double a = idx * (1.0 / (double)fn);
|
||||
const double x = pen[0] * t(a, 2) + c1[0] * 2 * t(a, 1) * a + to[0] * a * a;
|
||||
const double y = pen[1] * t(a, 2) + c1[1] * 2 * t(a, 1) * a + to[1] * a * a;
|
||||
add_vertex(Vector2d(x, y));
|
||||
add_vertex(pen * pow(1-a, 2) +
|
||||
c1 * 2 * pow(1-a, 1) * a +
|
||||
to * pow(a, 2));
|
||||
}
|
||||
pen = to;
|
||||
}
|
||||
|
||||
// Cubic Bezier curve
|
||||
void DrawingCallback::curve_to(Vector2d c1, Vector2d c2, Vector2d to)
|
||||
{
|
||||
for (unsigned long idx = 1;idx <= fn;idx++) {
|
||||
const double a = idx * (1.0 / (double)fn);
|
||||
const double x = pen[0] * t(a, 3) + c1[0] * 3 * t(a, 2) * a + c2[0] * 3 * t(a, 1) * a * a + to[0] * a * a * a;
|
||||
const double y = pen[1] * t(a, 3) + c1[1] * 3 * t(a, 2) * a + c2[1] * 3 * t(a, 1) * a * a + to[1] * a * a * a;
|
||||
add_vertex(Vector2d(x, y));
|
||||
add_vertex(pen * pow(1-a, 3) +
|
||||
c1 * 3 * pow(1-a, 2) * a +
|
||||
c2 * 3 * pow(1-a, 1) * pow(a, 2) +
|
||||
to * pow(a, 3));
|
||||
}
|
||||
pen = to;
|
||||
}
|
||||
|
|
|
@ -56,8 +56,4 @@ private:
|
|||
std::vector<const class Geometry *> polygons;
|
||||
|
||||
void add_vertex(Vector2d v);
|
||||
|
||||
inline double t(double t, int exp) const {
|
||||
return pow(1.0 - t, exp);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue