-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.cpp
More file actions
92 lines (62 loc) · 1.82 KB
/
Copy pathinput.cpp
File metadata and controls
92 lines (62 loc) · 1.82 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
#include "input.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <math.h>
using namespace std;
input::input()
{
}
void input::load_data(string path){
vector<pair<double , double> > single_path;
string line;
ifstream myfile (path.c_str());
if (myfile.is_open())
{
pair<double , double> last_pos;
last_pos.first = -1000;
last_pos.second = -1000;
pair<double , double> shoot_pos;
bool added = false;
while ( getline (myfile,line) )
{
pair<double , double> pos;
if(line == "---------"){
if(single_path.size() != 0){
if(added == false){
single_path.push_back(shoot_pos);
}
all_paths.push_back(single_path);
}
single_path.clear();
continue;
}
int delimiter = line.find(',');
string x = line.substr(0 , delimiter);
string y = line.substr(delimiter + 2 , line.size());
double x_num = atof(x.c_str());
double y_num = -atof(y.c_str());
pos.first = x_num;
pos.second = y_num;
if(dist(last_pos , pos) > 5){
single_path.push_back(pos);
last_pos = pos;
added = true;
}
else{
added = false;
}
shoot_pos = pos;
}
myfile.close();
}
else{
cout << "Unable to open file";
}
//cout << all_paths.size() << endl;
}
double input::dist(pair<double, double> point1, pair<double, double> point2){
double d =sqrt( pow(point1.first - point2.first , 2) + pow(point1.second - point2.second , 2) );
return d;
}