diff --git a/html/images/space.svg b/html/images/space.svg
index afd801b..dbe1bb4 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -424,6 +424,13 @@
});
}
+ function perpIntxn(baseSlope, xa, ya, xc, yc) {
+ const altitudeSlope = 1 / -baseSlope;
+ const isx = (-altitudeSlope * xc + yc + baseSlope * xa - ya) / (baseSlope - altitudeSlope);
+ const isy = altitudeSlope * isx - altitudeSlope * xc + yc;
+ return { x: isx, y: isy };
+ }
+
function drawLine(xa, ya, xb, yb) {
const el = document.createElementNS(namespaceURIsvg, 'line');
el.setAttribute('x1', xa);
@@ -455,40 +462,28 @@
const baseSlope = slope({ xa, ya, xb, yb });
- console.log("slope of base", baseSlope);
+ // console.log("slope of base", baseSlope);
if (baseSlope === -Infinity) {
- console.log("foot", xa + shipRadius, yc);
+ // console.log("foot", xa + shipRadius, yc);
} else if (baseSlope === Infinity) {
- console.log("foot", xa - shipRadius, yc);
+ // console.log("foot", xa - shipRadius, yc);
} else if (Object.is(baseSlope, 0)) {
- console.log("foot", xc, ya - shipRadius);
+ // console.log("foot", xc, ya - shipRadius);
} else if (Object.is(baseSlope, -0)) {
- console.log("foot", xc, ya + shipRadius);
+ // console.log("foot", xc, ya + shipRadius);
} else {
- console.log(xa, ya, xb, yb);
- // 10, 40, 20, 20
- // altitude slope (perpendicular of base)
- const altitudeSlope = 1 / -baseSlope;
- // point-slope formula
- // y - ya = baseSlope * (x - xa)
- // line equation of the base
- // y = baseSlope * x - baseSlope * xa + ya
- // y = -2x - (-2 * 10) + 40
- // point-slope formula
- // y - yc = altitudeSlope * (x - xc)
- // line equation of the altitude
- // y = altitudeSlope * x - altitudeSlope * xc + yc
-
- // test point c 0, 20
-
- // baseSlope * x - baseSlope * xa + ya = altitudeSlope * x - altitudeSlope * xc + yc
- // baseSlope * x - altitudeSlope * x = -altitudeSlope * xc + yc + baseSlope * xa - ya
- const isx = (-altitudeSlope * xc + yc + baseSlope * xa - ya) / (baseSlope - altitudeSlope);
- const isy = altitudeSlope * isx - altitudeSlope * xc + yc;
- // should be (35, 30)
- console.log("foot coords", isx, isy);
- drawLine(isx, isy, xc, yc);
+ const foot = perpIntxn(baseSlope, xa, ya, xc, yc);
+ // console.log("foot", foot);
+ // drawLine(foot.x, foot.y, xc, yc)
+ const el = document.createElementNS(namespaceURIsvg, 'line');
+ el.setAttribute('x1', foot.x);
+ el.setAttribute('y1', foot.y);
+ el.setAttribute('x2', xc);
+ el.setAttribute('y2', yc);
+ // this point should be the position of the ship to make it
+ // adjacent to the collision edge without overlapping it
+ console.log(el.getPointAtLength(5));
}
// https://en.wikipedia.org/wiki/Altitude_(triangle)#Altitude_in_terms_of_the_sides
@@ -584,7 +579,7 @@
console.log("a", "position", position, s.position);
s.velocity = { x: 0, y: 0 };
} else if (s.collision) {
- console.log("b", position, s.position);
+ console.log("b", s.position, s.collision);
s.velocity = { x: 0, y: 0 };
s.position.y = Math.trunc(s.collision.edge.ya - 5);