(Flash) Dot product and the angle between two lines in 2D - Math and (Quasi) physics in AS3

| No Comments | No TrackBacks

Try dragging the points.

The dot product is a powerful vector operation and one of its most handy usage is to compute an angle between two lines.

The dot product in 2D

A·B = a1 * b1 + a2 * b2 = ||A|| * ||B|| * cos(θ) 
  • A and B are 2D vectors and A = [a1 a2], B = [b1, b2]
  • ||A|| represents is the the magnitude of vector A
  • θ is the angle between A and B

In the sample movie, the line AB represents the vector A and CD represents the vector B

sample movie and scripts

No TrackBacks

TrackBack URL: http://www.kynd.info/cp-bin/mt/mt-tb.cgi/44

Leave a comment