Jump to content

  • Log In with Google      Sign In   
  • Create Account


choffstein

Member Since 27 Jun 2004
Offline Last Active Mar 31 2011 07:28 PM
-----

#4506081 finding a perpendicular 2d vector

Posted by choffstein on 08 August 2009 - 02:18 PM


vector find_perp(vector v, double desired_length) {
v_length = sqrt(pow(v.x,2) + pow(v.y,2))
double scale_factor = desired_length / v_length
return vector(-desired_length * v.y, desired_length * v.x)
}





Basically what we are doing is 'normalizing' the input vector, turning it into a vector of length 1 ('unit' length, from the 'unit' circle -- i.e. a vector of length 1 must lie on the points of the unit circle).

Then we find the perpendicular vector, which is also of 'unit' length, and multiply its components by our desired length.


PARTNERS