summaryrefslogtreecommitdiff
path: root/frontend/_shared/math/collision.js
diff options
context:
space:
mode:
authorMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-25 20:50:12 -0500
committerMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-25 20:50:12 -0500
commit026abdb98ad30209df0e88795f25b1f74556585e (patch)
tree39c7e60ea78331ada41fc71bc5f6e5b91b5fd75c /frontend/_shared/math/collision.js
parentf0d1398b0d1b1a7c5bd1d4e0b3488b7f1aa74364 (diff)
Updated the sidebar for usability's sake
Diffstat (limited to 'frontend/_shared/math/collision.js')
-rw-r--r--frontend/_shared/math/collision.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/frontend/_shared/math/collision.js b/frontend/_shared/math/collision.js
new file mode 100644
index 0000000..74ec5d8
--- /dev/null
+++ b/frontend/_shared/math/collision.js
@@ -0,0 +1,23 @@
+/// <reference path="vec2.js" />
+/// <reference path="line2.js" />
+/// <reference path="circle.js" />
+/// <reference path="mat4.js" />
+
+/**
+ *
+ * @param {circle} pCricle
+ * @param {line2} pLine
+ */
+function lineCircleCollision2(pCricle, pLine) {
+ // We have a triangle formed by circle's position P and the two points of the line, A and B.
+ var lSlope = (pCricle.position.y - pLine.start.y) / (pCricle.position.x - pLine.start.x),
+ lAngle = Math.atan(lSlope),
+ lAngleDiff = lAngle - pLine.angle,
+ lPositionToStart = subVec2(pCricle.position, pLine.start),
+ lPosToStartLength = length2(lPositionToStart),
+ lHeight = lPosToStartLength * Math.sin(lAngleDiff);
+
+ if (Math.abs(lHeight - pCricle.radius) < pCricle.radius) {
+ console.log('Intersection');
+ }
+} \ No newline at end of file