diff --git a/html/images/space.svg b/html/images/space.svg
index fdf2297..d071bc4 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -659,11 +659,35 @@
// console.log("ship landed", s, "edge", s.collision.edge.ya);
if (s.collision) {
// console.log("a");
- s.velocity = { x: 0, y: 0 };
const baseSlope = slope(s.collision.edge);
+ const { xa, ya, xb, yb } = s.collision.edge;
+ const baseLine = { x1: xa, y1: ya, x2: xb, y2: yb };
+
+ const velocityLine = {
+ x1: s.position.x,
+ y1: s.position.y,
+ x2: s.position.x + s.velocity.x,
+ y2: s.position.y + s.velocity.y
+ };
+
+ const baseNrmlIntxn = perpIntxn(baseSlope, xa, ya, s.position.x, s.position.y);
+ const baseVelIntxn = lineIntxnPt(baseLine, velocityLine);
+ const baseSegLength = distance(baseNrmlIntxn.x, baseNrmlIntxn.y , baseVelIntxn.x, baseVelIntxn.y);
+ const normalSegLength = distance(baseNrmlIntxn.x, baseNrmlIntxn.y, s.position.x, s.position.y);
+ const theta = Math.atan(normalSegLength / baseSegLength);
+ const h = 5 / Math.sin(theta);
+ const cl = document.createElementNS(namespaceURIsvg, 'line');
+ cl.setAttribute('x1', baseVelIntxn.x);
+ cl.setAttribute('y1', baseVelIntxn.y);
+ cl.setAttribute('x2', s.position.x);
+ cl.setAttribute('y2', s.position.y);
+ console.log("h", h);
+
+ const clPt = cl.getPointAtLength(h);
+ console.log("clPt", clPt);
+
const normalSlope = 1 / -baseSlope;
const radAngle = Math.atan(normalSlope);
- const { xa, ya, xb, yb } = s.collision.edge;
const foot = perpIntxn(baseSlope, xa, ya, xc, yc);
const el = document.createElementNS(namespaceURIsvg, 'line');
el.setAttribute('x1', foot.x);
@@ -683,7 +707,7 @@
// console.log("foot", foot, "line", el, "length", el.getTotalLength());
svg.appendChild(el);
// console.log(el, el.getTotalLength());
- const collPt = el.getPointAtLength(5);
+ // const collPt = el.getPointAtLength(5);
// let l = drawLine(foot.x, foot.y, foot.x - posX, foot.y - posY);
// let l = drawLine(foot.x, foot.y, foot.x - posY, foot.y - posX);
// s.position = { x: foot.x - posY, y: foot.y - posX };
@@ -691,7 +715,10 @@
// console.log("ship position", s.position);
// console.log("line length", l.getTotalLength(), l, foot.x - posY, foot.y - posX);
- s.position = { x: xc, y: yc }
+ s.velocity = { x: 0, y: 0 };
+ // s.position = { x: xc, y: yc }
+ s.position = { x: clPt.x, y: clPt.y }
+ console.log("s.position", s.position);
s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
} else {
// console.log("c");
@@ -860,7 +887,7 @@
// console.log("S POSITION", s.position);
updateBullets(elapsed);
// updateEdges(position);
- updateLines(elapsed, collE, {x, y}, {x: s.position.x, y: s.position.y});
+ if (!s.collision) updateLines(elapsed, collE, {x, y}, s.position);
if (drawCollisionLines) updateTriangles(position);
// const collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));