<sxr filename="Nurbs.h"> <line>#ifndef Nurbs_h_</line> <line>#define Nurbs_h_</line> <line></line> <line>#include "Path.h"</line> <line>#include <vector></line> <line></line> <line><span class="keyword">namespace</span> <a href="Paths" title="namespace Paths" from="Paths" type="definition">Paths</a></line> <line>{</line> <line></line> <line><span class="comment">//. The Nurbs class. It implements a nurbs curve</span></line> <line><span class="comment">//. for the given order. It is a very powerful</span></line> <line><span class="comment">//. and flexible curve representation. For simpler</span></line> <line><span class="comment">//. cases you may prefer to use a `Bezier` curve.</span></line> <line><span class="comment">//.</span></line> <line><span class="comment">//. While non-rational curves are not sufficient to represent a circle,</span></line> <line><span class="comment">//. this is one of many sets of NURBS control points for an almost uniformly </span></line> <line><span class="comment">//. parameterized circle:</span></line> <line><span class="comment">//.</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |x | y | weight |</span></line> <line><span class="comment">//. +==+====+=============+</span></line> <line><span class="comment">//. |1 | 0 | 1 |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |1 | 1 | `sqrt(2)/2` |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |0 | 1 | 1 |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |-1| 1 | `sqrt(2)/2` |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |-1| 0 | 1 |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |-1| -1 | `sqrt(2)/2` |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |0 | -1 | 1 |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |1 | -1 | `sqrt(2)/2` |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//. |1 | 0 | 1 |</span></line> <line><span class="comment">//. +--+----+-------------+</span></line> <line><span class="comment">//.</span></line> <line><span class="comment">//. The order is three, the knot vector is {0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4}.</span></line> <line><span class="comment">//. It should be noted that the circle is composed of four quarter circles,</span></line> <line><span class="comment">//. tied together with double knots. Although double knots in a third order NURBS</span></line> <line><span class="comment">//. curve would normally result in loss of continuity in the first derivative,</span></line> <line><span class="comment">//. the control points are positioned in such a way that the first derivative is continuous.</span></line> <line><span class="comment">//. (From Wikipedia_ )</span></line> <line><span class="comment">//.</span></line> <line><span class="comment">//. .. _Wikipedia: http://en.wikipedia.org/wiki/NURBS</span></line> <line><span class="comment">//.</span></line> <line><span class="comment">//. Example::</span></line> <line><span class="comment">//.</span></line> <line><span class="comment">//. Nurbs<3> circle;</span></line> <line><span class="comment">//. circle.insert_control_point(0, Vertex(1., 0.), 1.);</span></line> <line><span class="comment">//. circle.insert_control_point(0, Vertex(1., 1.), sqrt(2.)/2.);</span></line> <line><span class="comment">//. ...</span></line> <line><span class="comment">//.</span></line> <line>template <size_t Order></line> <line><span class="keyword">class</span> <a href="Paths::Nurbs" title="class Paths::Nurbs" from="Paths::Nurbs" type="definition">Nurbs</a> : <span class="keyword">public</span> <a href="Path" title="class Path" from="Paths::Nurbs" type="reference">Path</a></line> <line>{</line> <line><span class="keyword">public</span>:</line> <line> <span class="comment">//. Create a new Nurbs curve.</span></line> <line> <a href="Paths::Nurbs::Nurbs()" title="member function Paths::Nurbs::Nurbs()" from="Paths::Nurbs" type="definition">Nurbs</a>();</line> <line> <span class="comment">//. Inserts a control point with the given weight.</span></line> <line><span class="comment"> //. The knot value determines the position in the sequence.</span></line> <line><span class="comment"> //.</span></line> <line><span class="comment"> //. Parameters:</span></line> <line><span class="comment"> //. :knot: the parameter value at which to insert a new knot</span></line> <line><span class="comment"> //. :vertex: the control point</span></line> <line><span class="comment"> //. :weight: the weight of the control point</span></line> <line> <span class="keyword">void</span> <a href="Paths::Nurbs::insert_control_point(double,const Vertex&,double)" title="member function Paths::Nurbs::insert_control_point(double,const Vertex&,double)" from="Paths::Nurbs" type="definition">insert_control_point</a>(<span class="keyword">double</span> knot, <span class="keyword">const</span> <a href="Vertex" title="struct Vertex" from="Paths::Nurbs" type="reference">Vertex</a> &vertex,</line> <line> <span class="keyword">double</span> weight);</line> <line> virtual <span class="keyword">void</span> <a href="Paths::Nurbs::draw()" title="member function Paths::Nurbs::draw()" from="Paths::Nurbs" type="definition">draw</a>();</line> <line><span class="keyword">private</span>:</line> <line> <span class="comment">//. The data...</span></line> <line> std::<a href="std::vector" title="class std::vector" from="Paths::Nurbs" type="reference">vector</a><<a href="Vertex" title="struct Vertex" from="Paths::Nurbs" type="reference">Vertex</a>> <a href="Paths::Nurbs::controls_" title="data member Paths::Nurbs::controls_" from="Paths::Nurbs" type="definition">controls_</a>;</line> <line> std::<a href="std::vector" title="class std::vector" from="Paths::Nurbs" type="reference">vector</a><<span class="keyword">double</span>> <a href="Paths::Nurbs::weights_" title="data member Paths::Nurbs::weights_" from="Paths::Nurbs" type="definition">weights_</a>;</line> <line> std::<a href="std::vector" title="class std::vector" from="Paths::Nurbs" type="reference">vector</a><<span class="keyword">double</span>> <a href="Paths::Nurbs::knots_" title="data member Paths::Nurbs::knots_" from="Paths::Nurbs" type="definition">knots_</a>;</line> <line>};</line> <line></line> <line>}</line> <line></line> <line>#endif</line> </sxr>