WIP: figure out normal vector but i don't th ink i need to

This commit is contained in:
2026-01-21 19:18:47 -08:00
parent 112c100057
commit 4b692194ae

View File

@@ -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]);

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 52 KiB