-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBezierMethod.cpp
More file actions
119 lines (92 loc) · 2.52 KB
/
BezierMethod.cpp
File metadata and controls
119 lines (92 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "BezierMethod.h"
#include <iostream>
#include <fstream>
#include <cassert>
#include <cmath>
BezierMethod::BezierMethod(double Boundary_one, double Boundary_two)
{
m_step = 0.1;
CollocationPoints = new double[3];
results = new double[3];
TValues_one = new double[3];
TValues_two = new double[3];
TValues_zero = new double[3];
m_BoundaryOne = Boundary_one;
m_BoundaryTwo = Boundary_two;
}
BezierMethod::~BezierMethod()
{
delete[] CollocationPoints;
delete[] TValues_one;
delete[] TValues_two;
delete[] TValues_zero;
delete[] results;
}
double BezierMethod::SecondDerivative(double t)
{
return 1;
}
double BezierMethod::FirstDerivative(double t)
{
return 0;
}
double BezierMethod::m_Function(double t)
{
return -1;
}
double BezierMethod::RightHandSide(double t)
{
return 0;
}
void BezierMethod::getPoints()
{
double* results;
results = Evaluate(0.5);
CollocationPoints[0] = m_BoundaryOne;
CollocationPoints[1] = ((results[0]*m_BoundaryOne) + (results[2]*m_BoundaryTwo)-RightHandSide(0))/-results[1];
CollocationPoints[2] = m_BoundaryTwo;
}
double BezierMethod::BinomialCoefficient(int n, int i)
{
if(n == i or i == 0)
{
return 1;
}
return BinomialCoefficient(n-1,i-1) + BinomialCoefficient(n-1,i);
}
double* BezierMethod::Evaluate(double t)
{
double* myValues = new double[3];
TValues_two[0] = SecondDerivative(t)*2;
TValues_two[1] = SecondDerivative(t)*-4;
TValues_two[2] = SecondDerivative(t)*2;
TValues_one[0] = FirstDerivative(t)*(-2+(2*t));
TValues_one[1] = FirstDerivative(t)*(2-(4*t));
TValues_one[2] = FirstDerivative(t)*(2*t);
TValues_zero[0] = m_Function(t)*BinomialCoefficient(2,0)*pow(1-t,2);
TValues_zero[1] = m_Function(t)*BinomialCoefficient(2,1)*(1-t)*t;
TValues_zero[2] = m_Function(t)*BinomialCoefficient(2,2)*pow(t,2);
for (int i = 0; i < 3; i ++)
{
myValues[i] = TValues_two[i] + TValues_one[i] + TValues_zero[i];
}
return myValues;
}
void BezierMethod::Solve()
{
getPoints();
}
void BezierMethod::Print()
{
Solve();
double step = 0;
std::ofstream myFile;
myFile.open("data.dat");
while (step < 1)
{
myFile << step << "\t" << CollocationPoints[0]*BinomialCoefficient(2,0)*pow(1-step,2) +
CollocationPoints[1]*BinomialCoefficient(2,1)*(1-step)*(step) +
CollocationPoints[2]*BinomialCoefficient(2,2)*pow(step,2)<< "\t" << exp(step) << "\n";
step += m_step;
}
}