blob: 051f7666a9f5933a929606f2a89bd759badd546c [file] [log] [blame]
 Brad 439cafb 2017-11-11 15:31:54 -0500 [diff] [blame^] 1 package islandairport; 2 3 import java.lang.Math; 4 import java.awt.geom.Point2D; 5 6 7 // calculates angle between two points 8 // x1, y1 -> point a 9 // x2, y2 -> point b 10 public fun angleBetween(x1, y1, x2, y2) { 11 var dx = x2 - x2; 12 var dy = y2 - y1; 13 var angle = Math.atan2(dy, dx); 14 if (angle < 0) 15 return -angle; 16 return 2 * Math.PI - angle; 17 } 18 19 // Calculates the 2d distance between two points 20 // x1, y1 point a 21 // x2, y2 point b 22 public fun distanceBetween(x1, y1, x2, y2) { 23 return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); 24 } 25 26 // tests whether a point is on the given line 27 // px1, py1 -> the point to test 28 // x2, y2, x3, y3 -> the line 29 public fun onLine(px1, py1, x2, y2, x3, y3) { 30 var d23 = distanceBetween(x2, y2, x3, x3); 31 var d = distanceBetween(px1, py1, x3, y3) + distanceBetween(px1, py1, x2, y2); 32 var eps = 0.00000000001; 33 34 return (d + eps) > d23 && (d - eps) < d23; 35 }