Projection of a vector over a plane

From Director Online Wiki
Jump to: navigation, search

Copy and paste on a movie script:


  -----------------------------------------
  on projectVectorOnPlane vect, planeNormal
    -- both parameters are vectors
    -- vect is the vector we want to project
    -- planeNormal is a vector normal to the plane (that defines its orientation)
    -- only returns void (error) if planeNormal is (0,0,0)
    -- otherwise, returns a vector
    -- by Iñigo de Gracia
  -----------------------------------------
 
    if planeNormal.magnitude <> 1 then 
      if planeNormal.magnitude = 0 then return void
      planeNormal.normalize()
    end if
 
    normalComponent = vect.dot (planeNormal) * planeNormal
    return vect - normalComponent
  end

--Luna1999 09:11, 26 September 2008 (UTC)