-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathutils.cpp
58 lines (46 loc) · 1.42 KB
/
mathutils.cpp
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
#include "mathutils.h"
#include <cmath>
#include <iostream>
#include <math.h>
MathUtils::MathUtils()
{
}
double MathUtils::fonctionQuadratique(double min, double max, double x) {
return x<min?0.0:x>=max?1.0:1.0-pow((1.0-pow((x-min)/(max-min),2)),2);
}
double MathUtils::fonctionQuadratiqueInv(double min, double max, double x) {
return 1.0-fonctionQuadratique(min,max,x);
}
double MathUtils::interpolate(double before_p0, double p0, double p1, double after_p1, double t)
{
//Calcul des coefficients de notre polynôme
double a3 = -0.5*before_p0 + 1.5*p0 - 1.5*p1 + 0.5*after_p1;
double a2 = before_p0 - 2.5*p0 + 2*p1 - 0.5*after_p1;
double a1 = -0.5*before_p0 + 0.5*p1;
double a0 = p0;
//Calcul de la valeur de ce polynôme en t
return (a3 * t*t*t) + (a2 * t*t) + (a1 * t) + a0;
}
double MathUtils::ridge(double n, double s) {
return n>s?2*s-n:n;
}
double MathUtils::mod(double a, double b) {
while(a>b) {a-=b;}
return a;
}
double MathUtils::dabs(double d) {
return d>=0?d:-d;
}
double MathUtils::aireTriangle(const Vector2D & a, const Vector2D & b, const Vector2D & c)
{
double ab = a.distanceToPoint2D(b);
double ac = a.distanceToPoint2D(c);
double cb = c.distanceToPoint2D(b);
double s = (ab+ac+cb)/2;
return sqrt(s*(s-ab)*(s-ac)*(s-cb));
}
double MathUtils::random(double min, double max)
{
double f = (double)rand() / RAND_MAX;
return min + f * (max - min);
}