diff --git a/html/images/space.svg b/html/images/space.svg index e9e9bf4..aa33652 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -126,7 +126,9 @@ - + + + @@ -563,6 +565,9 @@ const Move = (() => { const velocityVectorMagnitude = Math.sqrt(v.y**2+v.x**2); const dotProduct = edgeVector.y*v.y + edgeVector.x*v.x; const normalVectorDotProduct = normalVector.y*v.y + normalVector.x*v.x; + // const velocityVectorCrossNormalVector = v.x * normalVector.y - v.y * normalVector.x; + const velocityVectorCrossNormalVector = v.y * normalVector.x - v.x * normalVector.y; + console.log("dotProduct", dotProduct, "normalVectorDotProduct", normalVectorDotProduct); const edgeTheta = Math.acos(dotProduct / (edgeVectorMagnitude * velocityVectorMagnitude)); const normalTheta = Math.acos(normalVectorDotProduct / (edgeVectorMagnitude * velocityVectorMagnitude)); @@ -570,17 +575,28 @@ const Move = (() => { console.log("VELOCITY", v); console.log("theta between edge vector and velocity vector", edgeTheta, "degrees", edgeTheta * 180 / Math.PI); console.log("theta between normal vector and velocity vector", normalTheta, "degrees", normalTheta * 180 / Math.PI); + console.log("cross product normal and velocity", velocityVectorCrossNormalVector); const newTheta = (Math.PI - normalTheta) * 2; - const newY = -Math.cos(newTheta) * velocityVectorMagnitude; - const newX = Math.sin(newTheta) * velocityVectorMagnitude; + // const newY = -Math.cos(newTheta) * velocityVectorMagnitude; + // const newX = Math.sin(newTheta) * velocityVectorMagnitude; + + let newY; + let newX; + if (velocityVectorCrossNormalVector < 0) { + newX = Math.cos(newTheta) * velocityVectorMagnitude; + newY = Math.sin(newTheta) * velocityVectorMagnitude; + } else { + newX = Math.sin(newTheta) * velocityVectorMagnitude; + newY = Math.cos(newTheta) * velocityVectorMagnitude; + } Velocity[entity_id] = { // x: v.x * Math.sin(thetaX) + v.y * Math.cos(thetaY), // y: v.y * Math.sin(thetaY) + v.x * Math.cos(thetaX) x: newX, // y: v.y * Math.sin(thetaY) + v.x * Math.cos(thetaX) - y: newY + y: -newY }; console.log("VELOCITY AFTER", Velocity[entity_id]); @@ -683,7 +699,7 @@ function init() { s.position = { x: 0, y: 0 }; // s.velocity = { x: 0, y: -10 }; - s.velocity = { x: 0, y: 10 }; + s.velocity = { x: -10, y: 0 }; s.angularVelocity = 0; // s. velocity = { x: -5*mult, y: 7*mult };