blob: 6fcc3a8ae57523bd09625e245e21da17ed14e27b [file] [log] [blame]
Brad439cafb2017-11-11 15:31:54 -05001package islandairport;
2
3import java.lang.Math;
4import java.awt.geom.Point2D;
5
6
Brad7c809ea2017-11-13 15:15:49 -05007public fun angleBetween(a, b) {
8 return angleBetween(a.getX(), a.getY(), b.getX(), b.getY());
9}
10
Brad439cafb2017-11-11 15:31:54 -050011// calculates angle between two points
12// x1, y1 -> point a
13// x2, y2 -> point b
14public fun angleBetween(x1, y1, x2, y2) {
15 var dx = x2 - x2;
16 var dy = y2 - y1;
17 var angle = Math.atan2(dy, dx);
18 if (angle < 0)
19 return -angle;
20 return 2 * Math.PI - angle;
21}
22
23// Calculates the 2d distance between two points
24// x1, y1 point a
25// x2, y2 point b
26public fun distanceBetween(x1, y1, x2, y2) {
27 return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
28}
29
30// tests whether a point is on the given line
31// px1, py1 -> the point to test
32// x2, y2, x3, y3 -> the line
33public fun onLine(px1, py1, x2, y2, x3, y3) {
Brad52c28e02017-11-13 14:33:59 -050034 var d23 = distanceBetween(x2, y2, x3, y3);
Brad439cafb2017-11-11 15:31:54 -050035 var d = distanceBetween(px1, py1, x3, y3) + distanceBetween(px1, py1, x2, y2);
36 var eps = 0.00000000001;
Brad439cafb2017-11-11 15:31:54 -050037 return (d + eps) > d23 && (d - eps) < d23;
38}