Javascript function that works like actionscript's normalize(1)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • biggusdickus
    New Member
    • Aug 2010
    • 2

    Javascript function that works like actionscript's normalize(1)

    I need a formula that returns normalize numbers for xy point - similar to actionscript's normalize() function.
    Code:
    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'm brand new to this form, so if it the answer is simple, please be adviced that I was dropped on my head when I was very young. However, if it's more complex then I'm Matt Damon and there's a job opening for a janitor at my school.

    Reply in Javascript - Thank you.
  • biggusdickus
    New Member
    • Aug 2010
    • 2

    #2
    found answer:
    var len = Math.sqrt(norma l.x * normal.x + normal.y * normal.y)
    normal.x/=len;
    normal.y/=len;

    Comment

    Working...