From 4b692194ae40f1a7cb71e7e52b446bacb2f75dd9 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Wed, 21 Jan 2026 19:18:47 -0800 Subject: [PATCH] WIP: figure out normal vector but i don't th ink i need to --- html/images/space.svg | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/html/images/space.svg b/html/images/space.svg index 74e298c..124a817 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -551,11 +551,34 @@ const Move = (() => { // 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; + const edgeVector = { x: run, y: rise }; + const normalVector = { x: rise, y: -run }; + drawLine(p.x, p.y, p.x + normalVector.x, p.y + normalVector.y); + drawLine(p.x, p.x, p.x + v.x, p.y + v.y, "blue"); + 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; + console.log("dotProduct", dotProduct, "normalVectorDotProduct", normalVectorDotProduct); + const edgeTheta = Math.acos(dotProduct / (edgeVectorMagnitude * velocityVectorMagnitude)); + const normalTheta = Math.acos(normalVectorDotProduct / (edgeVectorMagnitude * velocityVectorMagnitude)); + 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); + 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: v.x * Math.sin(thetaX) + v.y * Math.cos(thetaY), + // y: v.y * Math.sin(thetaY) + v.x * Math.cos(thetaX) + x: v.y, + // y: v.y * Math.sin(thetaY) + v.x * Math.cos(thetaX) + y: 0 }; console.log("VELOCITY AFTER", Velocity[entity_id]);