-
Notifications
You must be signed in to change notification settings - Fork 0
/
BenchPress.java
133 lines (131 loc) · 4.45 KB
/
BenchPress.java
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.util.*;
import java.io.*;
import java.util.Scanner;
//Algorithm for Bench and Squad (since the two have similar motions)
public class BenchPress
{
public static int xpos = 0;
public static int ypos = 0;
public static final double threshold = 1.5;
public static ArrayList<double[]> data = new ArrayList<double[]>();
public static ArrayList<Double> xList = new ArrayList<Double>();
public static ArrayList<Double> yList = new ArrayList<Double>();
public static ArrayList<Double> timeList = new ArrayList<Double>();
public static void main(String []args)throws FileNotFoundException
{
readTextFile("data1.txt", xList, yList, timeList);
//displayData(data);
//System.out.println(data.get(19)[2]);
int a = callibrateStart(data);
System.out.println(stop(data));
//System.out.println(data.size());
//System.out.println(a);
//int x = callibrate(data);
System.out.println(positionx(data));
System.out.println(positiony(data));
System.out.println((data.get(501)[2] - data.get(500)[2])*data.get(501)[0]);
//if(stop(data))
//System.out.println("Just..... DO IT - Shia LaBeouf");
}
public static void readTextFile(String txtfile, ArrayList<Double> xlist, ArrayList<Double> ylist, ArrayList<Double> timelist)throws FileNotFoundException
{
FileInputStream fstream = new FileInputStream(txtfile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String data;
try
{
while ((data = br.readLine()) != null)
{
String[] tmp = data.split(" "); //Split space
//System.out.println(tmp[0]);
timelist.add(Double.parseDouble(tmp[0]));
xlist.add(Double.parseDouble(tmp[1]));
ylist.add(Double.parseDouble(tmp[2]));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
}
for(int i= 0; i < xlist.size(); i++)
{
addData(xlist, ylist, timelist, i);
}
}
public static void addData(ArrayList<Double> x,ArrayList<Double> y,ArrayList<Double> t,int a)
{
data.add(new double[]{x.get(a),y.get(a),t.get(a)});
}
public static void displayData(ArrayList<double[]> data)
{
for(int i = 0; i < data.size(); i++)
{
for(int j = 0; j < data.get(i).length; j++)
{
System.out.println(data.get(i)[j]);
}
}
}
public static boolean stop(ArrayList<double[]> a)
{
for(int i = 0; i < a.size(); i++)
{
if(a.get(i)[0] < .5 && a.get(i)[0] > -.5 && a.get(i)[1] < .5 && a.get(i)[1] > -.5)
return true;
}
return false;
}
public static double positionx(ArrayList<double[]> data)
{
double firstriemmansumx = 0;
double secondriemmansumx = 0;
ArrayList<Double> xsum1 = new ArrayList<Double>();
for(int i = 1; i < data.size(); i++)
{
firstriemmansumx += data.get(i)[0] * (data.get(i)[2]-data.get(i-1)[2]);
xsum1.add(firstriemmansumx);
}
for(int c = 1; c < xsum1.size(); c++)
{
secondriemmansumx += xsum1.get(c) * (data.get(c)[2]-data.get(c-1)[2]);
}
return secondriemmansumx;
}
public static double positiony(ArrayList<double[]> data)
{
double firstriemmansumy = 0;
double secondriemmansumy = 0;
ArrayList<Double> ysum1 = new ArrayList<Double>();
for(int i = 1; i < data.size(); i++)
{
firstriemmansumy += data.get(i)[1] * (data.get(i)[2]-data.get(i-1)[2]);
ysum1.add(firstriemmansumy);
}
for(int c = 1; c < ysum1.size(); c++)
{
secondriemmansumy += ysum1.get(c) * (data.get(c)[2]-data.get(c-1)[2]);
}
return secondriemmansumy;
}
public static boolean rightSpot(double rightx, double righty, ArrayList<double[]> data)
{
double diffy = Math.abs(positiony(data) - righty);
double diffx = Math.abs(positionx(data) - rightx);
return(diffy < threshold && diffx < threshold);
}
public static int callibrateStart(ArrayList<double[]> data)
{
int index = 0;
boolean found = false;
for(int i = 0; i < data.size() && !found; i++)
if(data.get(i)[0] > 0 || data.get(i)[1] > 0){
index = i;
found = true;
}
return index;
}
}