-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.java
44 lines (37 loc) · 1.2 KB
/
Helper.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
package aig;
import java.lang.Math;
public class Helper {
public static double calcXFromHeadingDistance(
double heading, double distance, double baseX)
{
return baseX + Math.sin(heading) * distance;
}
public static double calcYFromHeadingDistance(
double heading, double distance, double baseY)
{
return baseY + Math.cos(heading) * distance;
}
public static double calcHeadingFromPosition(
double startX, double startY, double targetX, double targetY)
{
return Math.atan2(targetX-startX,targetY-startY);
}
public static double calcDistanceFromPosition(
double startX, double startY, double targetX, double targetY)
{
double x = targetX-startX;
double y = targetY-startY;
return Math.sqrt(x*x+y*y);
}
public static double calcRelativeBearing(
double absoluteBearing, double heading)
{
double out = absoluteBearing - heading;
return plusMinusPI(out);
}
public static double plusMinusPI(double angle) {
if (angle > Math.PI) angle -= 2*Math.PI;
if (angle < -Math.PI) angle += 2*Math.PI;
return angle;
}
}