diff --git a/html/images/space.svg b/html/images/space.svg
index 705c4f9..483d649 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -492,7 +492,6 @@ const Move = (() => {
};
const contacts = detectContacts([px, py], p, v, s.radius, map, false);
- console.log("CONTACTS", contacts);
if (contacts.length !== 0) {
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
@@ -511,67 +510,15 @@ const Move = (() => {
console.log("INTENDED POSITION", p.x, p.y);
console.log("CONTACT POSITION", contact.position);
- // const m1 = slope({ xa: vx, ya: vy, xb: v.x, yb: v.y });
- // const m2 = slope(contact.edge);
- // const theta = Math.atan(Math.abs((m1-m2)/(1+m1*m2)));
- const thetaY = Math.atan((contact.edge.yb - contact.edge.ya)/(contact.edge.xb-contact.edge.xa));
- const thetaX = Math.atan((contact.edge.xb-contact.edge.xa)/(contact.edge.yb - contact.edge.ya));
- // const thetaX = Math.atan((contact.edge.xb-contact.edge.xa)/(contact.edge.yb - contact.edge.ya));
- const edgeSlope = slope(contact.edge);
const rise = contact.edge.yb-contact.edge.ya;
const run = contact.edge.xb-contact.edge.xa;
- console.log("rise", rise, "run", run);
-
- const edgeAngleTheta = Math.atan(rise/run);
- console.log("EDGEANGLETETASADFSDDFSF", edgeAngleTheta, "degrees", edgeAngleTheta * 180 / Math.PI);
- const edgeVector = { x: run, y: rise };
const normalVector = { x: rise, y: -run };
- console.log("edgeVector", edgeVector, "normalVector", normalVector);
- const edgeVectorMagnitude = Math.sqrt(edgeVector.x**2+edgeVector.y**2);
- 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));
-
- console.log("VELOCITY", v);
-
- drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue");
- drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green");
-
- // drawLine(p.x, p.x, p.x + v.x, p.y + v.y, "blue");
-
- // 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 newTheta = edgeTheta;
- // const newY = -Math.cos(newTheta) * velocityVectorMagnitude;
- // const newX = Math.sin(newTheta) * velocityVectorMagnitude;
- // console.log("theta", newTheta, "degrees", newTheta * 180 / Math.PI);
-
- console.log("theta between velocity vector and edge vector", newTheta, "degrees", newTheta * 180 / Math.PI);
+ drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector
+ drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector
let newY;
let newX;
- // if (velocityVectorCrossNormalVector < 0) {
- // if (velocityVectorCrossNormalVector > 0) {
- //
- // newX = Math.cos(newTheta) * velocityVectorMagnitude;
- // newY = Math.sin(newTheta) * velocityVectorMagnitude;
- // } else {
- // newX = Math.sin(newTheta) * velocityVectorMagnitude;
- // newY = Math.cos(newTheta) * velocityVectorMagnitude;
- // }
- // newX = Math.cos(newTheta) * v.x;
- // newY = -Math.sin(newTheta) * v.y;
- // newX = Math.cos(edgeAngleTheta) * velocityVectorMagnitude;
- // newY = -Math.sin(edgeAngleTheta) * velocityVectorMagnitude;
function vector(x, y) {
const vector = { x: x, y: y };
@@ -588,7 +535,6 @@ const Move = (() => {
const vec1 = vector(v.x, v.y);
const vec2 = vector(run, rise);
-
// From https://stackoverflow.com/a/14886099
// 1. Find the dot product of vec1 and vec2
@@ -621,30 +567,13 @@ const Move = (() => {
newX = prAvx - prBvx;
newY = prAvy - prBvy;
+ drawLine(p.x, p.y, p.x + normalVector.x , p.y + normalVector.y, "black"); // edge normal vector
+ drawLine(p.x, p.y, p.x + newX , p.y + newY, "blue"); // bounced velocity vector
+ Velocity[entity_id] = { x: newX, y: newY };
- // newX = v.x;
- // newY = -v.y;
-
- // what vector x,y for a vector that is newTheta away from edge vector?
-
- console.log("newX", newX, "newY", newY);
-
- drawLine(p.x, p.y, p.x + normalVector.x , p.y + normalVector.y, "black");
- drawLine(p.x, p.y, p.x + newX , p.y + newY, "blue");
-
- 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
- };
-
- console.log("VELOCITY AFTER", Velocity[entity_id]);
-
+ // TODO can't set position without ball getting stuck
// Position[entity_id] = { x: p.x, y: p.y };
- // console.log("contact", contact.edge);
// Position[entity_id] = contact.position;
}
} else {