summaryrefslogtreecommitdiff
path: root/frontend/_shared/math/point2.js
diff options
context:
space:
mode:
authorMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-27 17:32:32 -0500
committerMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-27 17:32:32 -0500
commitd1b528b01796601c2bfea7b1a9813e5907e1c728 (patch)
tree77e2200e930fcad2166edf1e3d31d4cd1211db56 /frontend/_shared/math/point2.js
parent026abdb98ad30209df0e88795f25b1f74556585e (diff)
Close to being done on line-circle collisions, but it appears we're running into a rotation problem. Going to work on square-line collisions in the meantime
Diffstat (limited to 'frontend/_shared/math/point2.js')
-rw-r--r--frontend/_shared/math/point2.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/frontend/_shared/math/point2.js b/frontend/_shared/math/point2.js
new file mode 100644
index 0000000..eeacd91
--- /dev/null
+++ b/frontend/_shared/math/point2.js
@@ -0,0 +1,16 @@
+function point2(x = 0, y = 0) {
+ return { x: x, y: y };
+}
+
+function distanceFromPoint2ToLine2(pPoint, pLine) {
+ // Check out this wikapedia article for more information:
+ // https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
+ var x0 = pPoint.x,
+ y0 = pPoint.y,
+ x1 = pLine.start.x,
+ y1 = pLine.start.y,
+ x2 = pLine.end.x,
+ y2 = pLine.end.y;
+
+ return Math.abs((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)) / Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
+} \ No newline at end of file