COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BezierCurve Class Reference

#include <BezierCurve.h>

Public Member Functions

 BezierCurve ()
 
 BezierCurve (size_t numberOfStepsOnCurve)
 
std::vector< CLPointcurvePts (const std::vector< CLPoint > &pts)
 

Private Member Functions

C_FLOAT64 bernstein (C_INT32 i, C_INT32 n, C_FLOAT64 t)
 
CLPoint bezierPt (C_FLOAT64 t, std::vector< CLPoint > pts)
 
void init ()
 
C_FLOAT64 multiplyFromTo (C_INT32 n1, C_INT32 n2)
 

Private Attributes

C_FLOAT64 dt
 
size_t steps
 
C_FLOAT64 t
 

Detailed Description

Definition at line 37 of file BezierCurve.h.

Constructor & Destructor Documentation

BezierCurve::BezierCurve ( )

Definition at line 32 of file BezierCurve.cpp.

References init().

33 {
34  init();
35 }
BezierCurve::BezierCurve ( size_t  numberOfStepsOnCurve)

Definition at line 37 of file BezierCurve.cpp.

References steps, and t.

38 {
39  steps = numberOfStepsOnCurve;
40  t = 1.0 / steps;
41 }
C_FLOAT64 t
Definition: BezierCurve.h:45
size_t steps
Definition: BezierCurve.h:46

Member Function Documentation

C_FLOAT64 BezierCurve::bernstein ( C_INT32  i,
C_INT32  n,
C_FLOAT64  t 
)
private

Definition at line 79 of file BezierCurve.cpp.

References C_FLOAT64, and multiplyFromTo().

Referenced by bezierPt(), and curvePts().

80 {
81 
82  // first compute n over i
83  C_FLOAT64 top = multiplyFromTo(n - i + 1, n);
84  C_FLOAT64 bottom = multiplyFromTo(1, i);
85 
86  return (top / bottom * pow(t, (C_FLOAT64)i) * pow(1.0 - t, (C_FLOAT64)n - i));
87 }
C_FLOAT64 t
Definition: BezierCurve.h:45
C_FLOAT64 multiplyFromTo(C_INT32 n1, C_INT32 n2)
#define C_FLOAT64
Definition: copasi.h:92
CLPoint BezierCurve::bezierPt ( C_FLOAT64  t,
std::vector< CLPoint pts 
)
private

Definition at line 89 of file BezierCurve.cpp.

References bernstein(), C_FLOAT64, and C_INT32.

90 {
91  C_INT32 i;
92  C_FLOAT64 x = 0.0;
93  C_FLOAT64 y = 0.0;
94 
95  C_INT32 n = (C_INT32) pts.size() - 1;
96 
97  for (i = 0; i <= n; i++)
98  {
99  x += bernstein(i, n, t) * pts[i].getX();
100  y += bernstein(i, n, t) * pts[i].getY();
101  }
102 
103  return CLPoint(x, y);
104 }
C_FLOAT64 t
Definition: BezierCurve.h:45
C_FLOAT64 bernstein(C_INT32 i, C_INT32 n, C_FLOAT64 t)
Definition: BezierCurve.cpp:79
#define C_INT32
Definition: copasi.h:90
Definition: CLBase.h:54
#define C_FLOAT64
Definition: copasi.h:92
std::vector< CLPoint > BezierCurve::curvePts ( const std::vector< CLPoint > &  pts)

Definition at line 49 of file BezierCurve.cpp.

References bernstein(), C_FLOAT64, C_INT32, dt, and t.

Referenced by CGraphCurve::invertOrderOfPoints().

50 {
51  C_FLOAT64 x;
52  C_FLOAT64 y;
53  std::vector<CLPoint>points;
54  points = std::vector<CLPoint>();
55 
56  C_FLOAT64 t = 0.0;
57 
58  C_INT32 i;
59  C_INT32 n = (C_INT32) pts.size() - 1;
60 
61  while (t <= 1.0000001)
62  {
63  x = 0.0;
64  y = 0.0;
65 
66  for (i = 0; i <= n; i++)
67  {
68  x += bernstein(i, n, t) * pts[i].getX();
69  y += bernstein(i, n, t) * pts[i].getY();
70  }
71 
72  points.push_back(CLPoint(x, y));
73  t += dt;
74  }
75 
76  return points;
77 }
C_FLOAT64 t
Definition: BezierCurve.h:45
C_FLOAT64 bernstein(C_INT32 i, C_INT32 n, C_FLOAT64 t)
Definition: BezierCurve.cpp:79
#define C_INT32
Definition: copasi.h:90
Definition: CLBase.h:54
C_FLOAT64 dt
Definition: BezierCurve.h:47
#define C_FLOAT64
Definition: copasi.h:92
void BezierCurve::init ( )
private

Definition at line 43 of file BezierCurve.cpp.

References dt, and steps.

Referenced by BezierCurve().

44 {
45  steps = 100;
46  dt = 0.01;
47 }
C_FLOAT64 dt
Definition: BezierCurve.h:47
size_t steps
Definition: BezierCurve.h:46
C_FLOAT64 BezierCurve::multiplyFromTo ( C_INT32  n1,
C_INT32  n2 
)
private

Definition at line 108 of file BezierCurve.cpp.

References C_FLOAT64, and C_INT32.

Referenced by bernstein().

109 {
110  C_INT32 i;
111  C_FLOAT64 prod = 1;
112 
113  if (n2 >= n1)
114  {
115  for (i = n1; i <= n2; i++)
116  prod *= (C_FLOAT64)i;
117  }
118 
119  return prod;
120 }
#define C_INT32
Definition: copasi.h:90
#define C_FLOAT64
Definition: copasi.h:92

Member Data Documentation

C_FLOAT64 BezierCurve::dt
private

Definition at line 47 of file BezierCurve.h.

Referenced by curvePts(), and init().

size_t BezierCurve::steps
private

Definition at line 46 of file BezierCurve.h.

Referenced by BezierCurve(), and init().

C_FLOAT64 BezierCurve::t
private

Definition at line 45 of file BezierCurve.h.

Referenced by BezierCurve(), and curvePts().


The documentation for this class was generated from the following files: