Synopsis Cross-Reference

File: Nurbs.h
 1#ifndef Nurbs_h_
 2#define Nurbs_h_
 3
 4#include "Path.h"
 5#include <vector>
 6
 7namespace Paths
 8{
 9
10//. The Nurbs class. It implements a nurbs curve
11//. for the given order. It is a very powerful
12//. and flexible curve representation. For simpler
13//. cases you may prefer to use a `Bezier` curve.
14//.
15//. While non-rational curves are not sufficient to represent a circle,
16//. this is one of many sets of NURBS control points for an almost uniformly 
17//. parameterized circle:
18//.
19//. +--+----+-------------+
20//. |x |  y | weight      |
21//. +==+====+=============+
22//. |1 |  0 | 1           |
23//. +--+----+-------------+
24//. |1 |  1 | `sqrt(2)/2` |
25//. +--+----+-------------+
26//. |0 |  1 | 1           |
27//. +--+----+-------------+
28//. |-1|  1 | `sqrt(2)/2` |
29//. +--+----+-------------+
30//. |-1|  0 | 1           |
31//. +--+----+-------------+
32//. |-1| -1 | `sqrt(2)/2` |
33//. +--+----+-------------+
34//. |0 | -1 | 1           |
35//. +--+----+-------------+
36//. |1 | -1 | `sqrt(2)/2` |
37//. +--+----+-------------+
38//. |1 |  0 | 1           |
39//. +--+----+-------------+
40//.
41//. The order is three, the knot vector is {0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4}.
42//. It should be noted that the circle is composed of four quarter circles,
43//. tied together with double knots. Although double knots in a third order NURBS
44//. curve would normally result in loss of continuity in the first derivative,
45//. the control points are positioned in such a way that the first derivative is continuous.
46//. (From Wikipedia_ )
47//.
48//. .. _Wikipedia: http://en.wikipedia.org/wiki/NURBS
49//.
50//. Example::
51//.
52//.   Nurbs<3> circle;
53//.   circle.insert_control_point(0, Vertex(1., 0.), 1.);
54//.   circle.insert_control_point(0, Vertex(1., 1.), sqrt(2.)/2.);
55//.   ...
56//.
57template <size_t Order>
58class Nurbs : public Path
59{
60public:
61  //. Create a new Nurbs curve.
62  Nurbs();
63  //. Inserts a control point with the given weight.
64  //. The knot value determines the position in the sequence.
65  //.
66  //. Parameters:
67  //.   :knot: the parameter value at which to insert a new knot
68  //.   :vertex: the control point
69  //.   :weight: the weight of the control point
70  void insert_control_point(double knot, const Vertex &vertex,
71                            double weight);
72  virtual void draw();
73private:
74  //. The data...
75  std::vector<Vertex> controls_;
76  std::vector<double> weights_;
77  std::vector<double> knots_;
78};
79
80}
81
82#endif