Mogan_note4
如何画曲线
1public:
2 inline curve_rep () {}
3 inline virtual ~curve_rep () {}
4
5 inline virtual int nr_components () { return 1; }
6 // the number of components of the curve is useful for getting
7 // nice parameterizations when concatenating curves
8
9 virtual point evaluate (double t)= 0;
10 // gives a point on the curve for its intrinsic parameterization
11 // curves are parameterized from 0.0 to 1.0
12
13 array<point> rectify (double eps);
14 // returns a rectification of the curve, which, modulo reparameterization
15 // has a uniform distance of at most 'eps' to the original curve
16
17 virtual void rectify_cumul (array<point>& a, double eps)= 0;
18 // add rectification of the curve (except for the starting point)
19 // to an existing polysegment
20
21 /*
22 NOTE: more routines should be added later so that one
23 can reliably compute the intersections between curves
24 One might for instance take the following:
25 */
26 virtual double bound (double t, double eps)= 0;
27 // return delta such that |t' - t| < delta => |c(t') - c(t)| < eps.
28
29 virtual point grad (double t, bool& error)= 0;
30 // compute the first derivative at t.
31 // set error= true if this derivative does not exist.
32
33 virtual double curvature (double t1, double t2)= 0;
34 // compute a bound for the second derivative between t1 and t2.
35 /* FIXME: What is computed is *really* a bound for the curvature,
36 not for the norm of the second derivative. Make it precise
37 what it is that is computed exactly. */
38 // return a very large number if such a bound does not exist.
39
40 // returns the number of control points which belong to the curve.
41 // these control points are ordered and come first in pts & cips.
42 virtual int get_control_points (array<double>& abs, array<point>& pts,
43 array<path>& cip);
44
45 virtual array<double> find_closest_points (double t1, double t2, point p,
46 double eps);
47
48 virtual double find_closest_point (double t1, double t2, point p, double eps,
49 bool& found);
理解这段代码并用中文解释
这段代码定义了一个名为curve_rep的类,它是abstract_struct类的子类。以下是对代码的中文解释:
- curve_rep类具有默认构造函数和虚析构函数。
- nr_components()函数返回曲线的组件数,对于连接曲线时获取良好的参数化很有用。
- evaluate(double t)函数根据曲线的内在参数化,在曲线上给出一个点。曲线的参数化范围是从0.0到1.0。
- rectify(double eps)函数返回曲线的修正,它与原曲线的距离在重新参数化的情况下最多为’eps’。
- rectify_cumul(array& a, double eps)函数将曲线的修正(除起始点外)添加到现有的多段线中。
- bound(double t, double eps)函数返回一个delta值,使得当|t’ - t| < delta时,|c(t’) - c(t)| < eps。它用于计算曲线之间的交点。
- grad(double t, bool& error)函数计算t处的一阶导数,并设置error为true,如果该导数不存在。
- curvature(double t1, double t2)函数计算t1和t2之间的二阶导数的界限。如果不存在这样的界限,它将返回一个非常大的数。
- get_control_points(array& abs, array& pts, array& cip)函数返回属于曲线的控制点的数量。这些控制点在pts和cip中按顺序排列。
- find_closest_points(double t1, double t2, point p, double eps)函数查找曲线上与给定点p最接近的点,并返回其参数值的数组。
- find_closest_point(double t1, double t2, point p, double eps, bool& found)函数查找曲线上与给定点p最接近的点,并返回其参数值。如果找到了最接近的点,将设置found为true。
这段代码定义了一个抽象的曲线表示类,提供了计算曲线上点、修正、交点计算、曲率计算等功能的接口。具体的实现将在该类的派生类中完成。