Angle between lines

  scripts
  sprites
See inside
Instructions

Quick little demo in response to this forum topic:
http://scratch.mit.edu/discuss/topic/29930/

It shows how to calculate the angle between two lines, given the start and end co-ordinates of the lines.

Drag the dots to change the angle from the red line to the blue line.

Notes and Credits

* updated angle to show only 3dp again (Scratch now shows 6dp)

This uses the 2D "vector dot product" (see "Dot_product" on wikipedia) to find the cosine of the angle between the two lines.

It then also does an extra check for the orientation (i.e. whether it's clockwise or anticlockwise) by calculating the (signed) area of the triangle formed by the three points - if the area is positive then the angle is anticlockwise, so it makes the angle negative (which matches the convention used by Scratch for direction angles, and which is the opposite to the convention typically used by mathematicians).

Shared: 19 Feb 2014 Modified: 7 Jun 2014
Favorite this project 16
Love this project 24
Total views 552
View the remix tree  10
  
More projects by TheLogFather