-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollision-detect-fix.cpp
65 lines (43 loc) · 1.74 KB
/
collision-detect-fix.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
59
60
61
62
63
64
65
#include "ibex.h"
#include "vibes.h"
#include "tools.h"
#include <math.h>
using namespace std;
using namespace ibex;
int main(int argc, char** argv) {
Interval T(0,30);
double waypoints[2][2] = {{0,0},{40,50}};
double Pos1[2][2] = {{50,55},{60,65}};
IntervalVector obstacle1Pos(2, Pos1);
double Pos2[2][2] = {{25,35},{50,55}};
IntervalVector obstacle2Pos(2, Pos2);
IntervalVector obstaclesPos[2] = {obstacle1Pos, obstacle2Pos};
Interval boatSpeed;
boatSpeed = (sqrt(pow(waypoints[1][0],2)+pow(waypoints[1][1],2))/T.ub())*Interval(0.9,1.1);
Interval boatHead;
boatHead = acos(waypoints[1][0]/(sqrt(pow(waypoints[1][0],2)+pow(waypoints[1][1],2))))*Interval(0.9, 1.1);
double pos[2][2] ={{-1,1},{-1,1}};
IntervalVector boatInitPos(2, pos);
bool collisionRisk = 0;
vibes::beginDrawing();
vibes::newFigure("collision detection with fixed obstacles");
vibes::setFigureProperties(vibesParams("x", 100, "y", 100, "width", 800, "height", 800));
double t = T.lb();
double dt = 1;
Interval x,y;
while ( t<=T.ub()){
x = boatSpeed*cos(boatHead)*t + boatInitPos[0];
y = boatSpeed*sin(boatHead)*t + boatInitPos[1];
vibes::drawBox(x.lb(), x.ub(), y.lb(), y.ub(), "[blue]");
t+= dt;
}
for (int i = 0; i<2; i++){
if (collisionRisk == 0){
collisionRisk = collisionCondition(boatSpeed, boatInitPos[0], boatInitPos[1], boatHead, Interval(0,0), obstaclesPos[i][0], obstaclesPos[i][1], Interval(0,0), T);
}
vibes::drawBox(obstaclesPos[i][0].lb(), obstaclesPos[i][0].ub(), obstaclesPos[i][1].lb(), obstaclesPos[i][1].ub(), "[red]");
}
cout << collisionRisk << endl;
vibes::endDrawing();
return 0;
}