-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBogey.java
98 lines (80 loc) · 2.07 KB
/
Bogey.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
package backend;
public class Bogey
{
private double[] coords = new double[2]; // x then y
private double diameter;
private String filename;
private Roomba r;
public Bogey(Roomba r, double angleToBot, double distance, double diameter, String filename)// DISTANCE IN MM
{
this.r = r;
this.coords[0] = r.getX();
this.coords[1] = r.getY();
this.coords = calcCoords(angleToBot, distance);
if (diameter > 20)
{
this.diameter = 20;
}
else
{
this.diameter = diameter;
}
if (distance > 60)
{
this.diameter = 0;
}
this.filename = filename;
}
public Bogey(Roomba r, String filename)
{
this.r = r;
this.coords[0] = r.getX();
this.coords[1] = r.getY();
this.coords = calcSensorCoords();
this.diameter = 20;
this.filename = filename;
}
public double[] calcSensorCoords()
{
double roombaAngleRadians = Math.toRadians(r.getAngle() + 90);
double x = this.getX() - 19 * Math.cos(roombaAngleRadians);
double y = this.getY() - 19 * Math.sin(roombaAngleRadians);
double[] coordinates =
{ x, y };
return coordinates;
}
public double[] calcCoords(double angle, double distance)// DIST IN mm
{
System.out.print(r.getX());
System.out.print(r.getY());
double roombaAngleRadians = Math.toRadians(r.getAngle() + 90);
double radians = Math.toRadians(r.getAngle() - angle);
double offsetX = 0;
double offsetY = 0;
offsetX = distance * 1.557480135 * Math.sin(radians) + 19 * Math.cos(roombaAngleRadians);
offsetY = distance * 1.557480135 * Math.cos(radians) + 19 * Math.sin(roombaAngleRadians);
double x = r.getX() + offsetX;
double y = r.getY() - offsetY; // y-axis is inverted in Java graphics
double[] coordinates =
{ x, y };
System.out.println(coordinates[0]);
System.out.println(coordinates[1]);
return coordinates;
}
public double getDiameter()
{
return diameter;
}
public String getImage()
{
return filename;
}
public double getX()
{
return coords[0];
}
public double getY()
{
return coords[1];
}
}