The Dot product can also be calculated by (the asterisk should be a dot):
Or for a nth dimensional vector space:
Hope this helps, and what language is the code by the way. I've only programed in ADA
I'm having trouble understanding how this code calculates the dot product which I understand as |A||B|cos Ɵ
Multiplying the cordinates together seems too easy
* Calculates the dot product of this vector and another given vector.
* @param v2 Another Vector2D instance.
* @return Number The dot product of this vector and the one passed in as a parameter.
public function dotProd(v2:Vector2D):Number
return _x * v2.x + _y * v2.y;