diff --git a/html/images/space.svg b/html/images/space.svg
index c6fc061..5a053be 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -591,50 +591,45 @@ const Move = (() => {
const rise = contact.edge.yb-contact.edge.ya;
const run = contact.edge.xb-contact.edge.xa;
- // drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector
const det = v.x * rise - v.y * run;
- // drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector
-
- // contact.velocity = { x: prAvx - prBvx, y: prAvy - prBvy };
contact.velocity = bounceVector(v, run, rise);
// edge normal vector
- // drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black");
+ drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black");
// bounced velocity vector
// drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue");
- // const edgeNrmlVect = { x: rise, y: -run };
const edgeNrmlVect = vector(rise, -run);
- const velocityVect = vector(-vx, vy);
+ const velocityVect = vector(v.x, v.y);
console.log("velocity vector", velocityVect);
console.log("normal vector", edgeNrmlVect);
drawLine(px, py, px + velocityVect.x, py + velocityVect.y, "blue");
- drawLine(px, py, px + edgeNrmlVect.x, py + edgeNrmlVect.y);
- // vDotn = edgeNrmlVect.x * velocityVect.dx + edgeNrmlVect.y * velocityVect.dy;
const vn = edgeNrmlVect.x * velocityVect.dx + edgeNrmlVect.y * velocityVect.dy;
const vDotn = edgeNrmlVect.x * velocityVect.x + edgeNrmlVect.y * velocityVect.y;
- const f = vDotn / (edgeNrmlVect.x ** 2 + edgeNrmlVect.y ** 2);
+ console.log("V dot N", vDotn);
+ const denom = edgeNrmlVect.x ** 2 + edgeNrmlVect.y ** 2;
+ console.log("denom", denom);
const vOnNx = vn * velocityVect.dx + velocityVect.x;
const vOnNy = vn * velocityVect.dy + velocityVect.y;
- const prVonNx = edgeNrmlVect.y * f;
- const prVonNy = -edgeNrmlVect.x * f;
+ const pVect = {
+ x: vDotn / denom * edgeNrmlVect.x,
+ y: vDotn / denom * edgeNrmlVect.y
+ };
+ const reverseP = { x: -pVect.x, y: -pVect.y };
+
+ // add reverseP and v vectors together
+ const prVonNx = reverseP.x + v.x;
+ const prVonNy = reverseP.y + v.y;
- console.log("vOnNx, vOnNy", vOnNx, vOnNy)
console.log("prVonNx, prVonNy", prVonNx, prVonNy)
- // drawLine(contact.position.x, contact.position.y, contact.position.x + prVonNy, contact.position.y - prVonNx, "teal");
drawLine(contact.position.x, contact.position.y, contact.position.x + prVonNx, contact.position.y + prVonNy, "teal");
- // contact.velocity = { x: -prVonNx, y: prVonNy }
- // contact.velocity = { x: 16, y: 32 };
contact.velocity = { x: prVonNx, y: prVonNy };
- // Velocity[entity_id] = { x: -prVonNx, y: prVonNy };
Velocity[entity_id] = { x: prVonNx, y: prVonNy };
- // -15.999999999999998 31.999999999999996
-
// if (det < 0) {
// console.log("moving towards edge");
// console.log("current velocity", vx, vy);
@@ -750,10 +745,10 @@ function init() {
started = false;
const mult = 10;
- s.position = { x: 2.23, y: -10 };
- // s.velocity = { x: 0, y: -10 };
+ s.position = { x: 0, y: -10 };
+ s.velocity = { x: -10, y: 20 };
// s.velocity = { x: 10, y: 20 };
- s.velocity = { x: 0, y: 40 };
+ // s.velocity = { x: -20, y: 40 };
// s.velocity = { x: 0, y: 20000 };
s.angularVelocity = 0;