# Thread: how this code calculates the dot product

1. ## how this code calculates the dot product

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;
}

2. ## Dot Product

The Dot product can also be calculated by (the asterisk should be a dot):

$ * = x_1y_1 + x_2y_2$.

Or for a nth dimensional vector space:

$ * = \displaystyle\sum_{i=0}^{n}x_iy_i$.

Hope this helps, and what language is the code by the way. I've only programed in ADA

3. actionscript 3

4. That doesn't seem the same as

Calculating the Dot Product In 2D
Define your two vectors. Vector1 (x1, y1) and Vector2 (x2, y2).

DotProduct = (x1*x2 + y1*y2)

from
Dot Product