From 406c5d1357a8f625e4b5689b24ef26e8cf6578ec Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Sat, 3 Jan 2026 16:23:43 -0800 Subject: [PATCH] Simplify --- html/images/space.svg | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/html/images/space.svg b/html/images/space.svg index 145018f..7fab802 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -115,8 +115,11 @@ - - + + + + + @@ -194,7 +197,8 @@ const s = { position: { x: 0, y: 0 }, // 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: 0, y: -10 }, // velocity: { x: 10, y: 10 }, @@ -872,11 +876,12 @@ current = s.collision; // s.collision = detectCollisions(position, allWallCorners, collE); s.collision = cwcd.find(c => { - const positionSegLength = distance(xc, yc, x, y); - - if (!positionSegLength) return false; + if (xc === x && yc === y) return; 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 slopeps = slope(positionSeg); 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: 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 t = -((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)); const roundedT = +t.toFixed(2); @@ -896,7 +903,7 @@ // console.log("s", s, "t", t); // 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";