title: Normalise and Perpendicular Function in python
body: <p>I was going through a <strong><a href="http://drilian.com/2009/02/25/lightning-bolts/#uniquepost" rel="nofollow">blog</a></strong> on Creating Lightning effect in 2D game.I wanted to implement the same in python. However I am stuck at a place. </p>
  
  <p>Lets say <strong>startpoint</strong> and <strong>endPoint</strong> are co-ordinates in 2D plane , representing extreme points of a line segment.</p>
  
  <p>Lets look at following Code Snippet from the blog:</p>
  
  <pre><code>midPoint = Average(startpoint, endPoint);
  // Offset the midpoint by a random amount along the normal.
  midPoint += Perpendicular(Normalize(endPoint-startPoint))*RandomFloat(-offsetAmount,offsetAmount); 
  </code></pre>
  
  <p>.</p>
  
  <hr>
  
  <pre><code>Normalize(endPoint-startPoint):
  </code></pre>
  
  <p>That line gets a unit vector (vector of length 1) from startPoint to endPoint</p>
  
  <hr>
  
  <pre><code>Perpendicular(Normalize(endPoint-startPoint))
  </code></pre>
  
  <p>then gets a vector perpendicular to that (i.e. at right angles to the line)</p>
  
  <hr>
  
  <p>I am not a regular python coder. Is there any in-built <strong>Normalise</strong> and <strong>Perpendicular</strong> Function in python that would help me in implementing the above code in python.</p>