-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (41 loc) · 1.64 KB
/
main.cpp
File metadata and controls
50 lines (41 loc) · 1.64 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
#include <codac>
using namespace std;
using namespace codac2;
int main(){
// Representation of centered form using zonotopes
Figure2D fig4 ("SpiralCentered",GraphicOutput::VIBES|GraphicOutput::IPE);
fig4.set_window_properties({500,50},{500,500});
fig4.set_axes(axis(0,{-10,10}), axis(1,{-10,10}));
double a=0.5;
ScalarVar t;
// we use Fermat's spiral
AnalyticFunction f1 ({t},{a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)});
double dt=0.2;
double time=0.0;
while (time<100.0) {
Interval T(time,time+dt);
// using eval_<true> would be easier, but it's not allowed :(
IntervalVector df = f1.diff(T);
if (df.is_empty() || df.is_unbounded()) {
/* not differentiable, we use a box */
IntervalVector bx = f1.eval(T);
fig4.draw_box(bx,{Color::blue(),Color::yellow(0.1)});
} else {
IntervalVector cent = f1.eval(T.mid());
// f(t) \in cent + df (t-T.mid())
// \in cent.mid + [-1,1] * T.rad*df.mid + [-1,1]*cent.rad +
// [-1,1] * T.rad*df.rad
Vector inflationbox = cent.rad() + T.rad()*df.rad();
Matrix v (2,3);
v << (T.rad()*df.mid()), Vector({ inflationbox[0], 0.0 }), Vector({ 0.0, inflationbox[1] });
fig4.draw_zonotope({cent.mid(),v},{{Color::red(),Color::yellow(0.1)},"zonotopes"});
Parallelepiped p = f1.parallelepiped_eval(T);
fig4.draw_parallelepiped(p,{{Color::black(),Color::green(0.1)},"parallelepipeds"});
Polytope p2 = f1.polytope_eval(T);
fig4.draw_polytope(p2,{{Color::black(),Color::red(0.1)},"polytopes"});
}
time = time+dt;
}
AnalyticTraj traj4 (f1,{0,100});
fig4.draw_trajectory(traj4,Color::black());
}