This commit is contained in:
2026-01-03 16:23:43 -08:00
parent 8db51f8870
commit 406c5d1357

View File

@@ -115,8 +115,11 @@
<!-- <polygon class="wall" points="10,-50 3,-50 3,-60 10,-60" /> --> <!-- <polygon class="wall" points="10,-50 3,-50 3,-60 10,-60" /> -->
<!-- <polygon class="wall" points="-10,50 -3,50 -3,60 -10,60" /> --> <!-- <polygon class="wall" points="-10,50 -3,50 -3,60 -10,60" /> -->
<polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> <!-- <polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> -->
<polygon class="wall" points="-20,50 -10,50 -10,60 -20,60" /> <!-- <polygon class="wall" points="-20,50 -10,50 -10,60 -20,60" /> -->
<polygon class="wall" points="-20,-50 -10,-50 -10,-60 -20,-60" />
<polygon class="wall" points="20,50 10,50 10,60 20,60" />
<!-- <polygon class="wall" points="-10,20 10,10 10,20" /> --> <!-- <polygon class="wall" points="-10,20 10,10 10,20" /> -->
<!-- <polygon class="wall" points="20,20 40,20 40,40 20,40" /> --> <!-- <polygon class="wall" points="20,20 40,20 40,40 20,40" /> -->
@@ -194,7 +197,8 @@
const s = { const s = {
position: { x: 0, y: 0 }, position: { x: 0, y: 0 },
// velocity: { x: 5, y: -10 }, // velocity: { x: 5, y: -10 },
velocity: { x: 5*mult, y: -10*mult }, velocity: { x: -5*mult, y: -10*mult },
// velocity: { x: 5*mult, y: -10*mult },
// velocity: { x: -5*mult, y: 10*mult }, // velocity: { x: -5*mult, y: 10*mult },
// velocity: { x: 0, y: -10 }, // velocity: { x: 0, y: -10 },
// velocity: { x: 10, y: 10 }, // velocity: { x: 10, y: 10 },
@@ -872,11 +876,12 @@
current = s.collision; current = s.collision;
// s.collision = detectCollisions(position, allWallCorners, collE); // s.collision = detectCollisions(position, allWallCorners, collE);
s.collision = cwcd.find(c => { s.collision = cwcd.find(c => {
const positionSegLength = distance(xc, yc, x, y); if (xc === x && yc === y) return;
if (!positionSegLength) return false;
const d = distance(c.corner.x, c.corner.y, xc, yc); const d = distance(c.corner.x, c.corner.y, xc, yc);
if (d <= shipRadius) return;
const positionSeg = { xa: xc, ya: yc, xb: x, yb: y }; const positionSeg = { xa: xc, ya: yc, xb: x, yb: y };
const slopeps = slope(positionSeg); const slopeps = slope(positionSeg);
const posNormIntxn = perpIntxn(slopeps, x, y, c.corner.x, c.corner.y); const posNormIntxn = perpIntxn(slopeps, x, y, c.corner.x, c.corner.y);
@@ -886,6 +891,8 @@
const { xa: x1, ya: y1, xb: x2, yb: y2 } = positionSeg; const { xa: x1, ya: y1, xb: x2, yb: y2 } = positionSeg;
const { xa: x3, ya: y3, xb: x4, yb: y4 } = cornerSeg; const { xa: x3, ya: y3, xb: x4, yb: y4 } = cornerSeg;
// https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments
// https://en.wikipedia.org/wiki/Cramer%27s_rule#Explicit_formulas_for_small_systems
const s = ((x3-x1)*(y4-y3)-(x4-x3)*(y3-y1))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)); const s = ((x3-x1)*(y4-y3)-(x4-x3)*(y3-y1))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1));
const t = -((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)); const t = -((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1));
const roundedT = +t.toFixed(2); const roundedT = +t.toFixed(2);
@@ -896,7 +903,7 @@
// console.log("s", s, "t", t); // console.log("s", s, "t", t);
// console.log("d", d, "shipRadius", shipRadius); // console.log("d", d, "shipRadius", shipRadius);
return d <= shipRadius || (s >= 0 && roundedT <= 1); return s >= 0 && roundedT <= 1;
}); });
// legs.style.display = !legs.style.display || legs.style.display === "none" ? "initial" : "none"; // legs.style.display = !legs.style.display || legs.style.display === "none" ? "initial" : "none";

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB