Help with an equation

I’m trying to calculate an angle, but it’s only working correctly at certain angles. I was thinking it might have to do with the Math.acos function, does anyone have any ideas why it might not be working?

var x = A-C;
var y = B-D;
var top = x*x+y*y;
var etan = Math.tan(E*3.1416/180);
var h = top/(2*x+2*y*etan);
var k = top/(2*y+2*x/etan);
var p = Math.sqrt(x*x+y*y);
var q = Math.sqrt(h*h+k*k);
var r = Math.sqrt(Math.pow(h-x,2)+Math.pow(k-y,2));
return Math.acos((r*r+q*q-p*p)/
(2*r*q))*180/3.1416;

This desmos graph is where I came up with the formulas, it works fine for all quadrants and situations, but it doesn’t work in all situations in flowlab; so it must be something wrong with my implementation in flowlab, not the calculations themselves.

This is the game. You can find the code in

connectionNode>Drag>DragInteraction>Blueprint

2 Likes

ok so…I realized that I just finish what I had planned to do lol. I needed that angle in addition to another one to get the total direction I wanted, so I think it might work after I do that

2 Likes

And look at that, it works! I spent several hours deriving and equation only to realize I was looking for the wrong angle… I feel stupid, but at least it works now!

1 Like

This is so cool!

1 Like