I need a formula that returns normalize numbers for xy point - similar to actionscript's normalize() function.
var normal = {x:pt1.x-pt2.x,y:pt1.y-pt2.y};
normal = Normalize(1) // this I do not know how to implement in Javascript
I think the as3 normalize function is just a way to scale a unit vector:
function normalize(point, scale) {
var norm = Math.sqrt(point.x * point.x + point.y * point.y);
if (norm != 0) { // as3 return 0,0 for a point of zero length
point.x = scale * point.x / norm;
point.y = scale * point.y / norm;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With