V-ART
bezier.cpp
Go to the documentation of this file.
1 
5 #include "vart/bezier.h"
6 #include <cassert>
7 
9  // Allocate memory
10  controlPoints.reserve(4);
11  // Set the number of control points. It seems to exist no way of setting the
12  // number of control points without initializing all of them.
14 }
15 
17  assert (i < 4);
18  assert (i >= 0);
19  return controlPoints[i];
20 }
21 
22 void VART::Bezier::SetControlPoint(int i, const VART::Point4D& point) {
23  assert (i < 4);
24  assert (i >= 0);
25  controlPoints[i] = point;
26 }
27 
28 void VART::Bezier::GetPoint(double t, VART::Point4D* result) {
29  double invT = 1-t; // Cache this common value
30  double t2 = t*t; // Cache this common value
31  VART::Point4D p0(controlPoints[0]);
32  VART::Point4D p1(controlPoints[1]);
33  VART::Point4D p2(controlPoints[2]);
34  VART::Point4D p3(controlPoints[3]);
35 
36  p0 *= invT*invT*invT;
37  p1 *= 3*t*invT*invT;
38  p2 *= 3*t2*invT;
39  p3 *= t2*t;
40  *result = p0 + p1 + p2 + p3;
41 }
Points and vectors using homogeneous coordinates.
Definition: point4d.h:22
std::vector< Point4D > controlPoints
Definition: curve.h:30
Point4D GetControlPoint(int i)
Returns a copy a control point.
Definition: bezier.cpp:16
Header file for V-ART class "Bezier".
static const Point4D & ORIGIN()
The (0,0,0,1) point.
Definition: point4d.cpp:61
void SetControlPoint(int i, const Point4D &point)
Assigns a (copy of a) control point.
Definition: bezier.cpp:22
virtual void GetPoint(double t, Point4D *result)
Returns a point of the curve.
Definition: bezier.cpp:28