Deriving an angle from three points

Colin Holgate coiin at verizon.net
Wed Dec 16 11:01:42 EST 2009


On Dec 16, 2009, at 1:21 AM, Mark Swindell wrote:

> 40,116
> 98,186
> 132,118
> 
> How would one determine the angle created from three points, such as those above?


All of the suggested scripts seem quite long. Try putting this script into three buttons. The script uses the Other Mark's way of dragging the button around (and it doesn't hilite the button as he claims):

on mouseDown
    repeat until the mouse is up with messages
         set the loc of me to the mouseLoc
         wait 0 millisecs with messages
      end repeat      
   put 180 - angler(loc of btn 1,loc of btn 2,loc of btn 3)/pi*180
end mouseDown
function angler p1, p2, p3
   put atan2(item 2 of p2-item 2 of p1,item 1 of p2 - item 1 of p1) into angle1
   put atan2(item 2 of p3-item 2 of p2,item 1 of p3 - item 1 of p2) into angle2
   return abs(angle2-angle1)
end angler

The bit that calculates the angle could be done in a single line:

put 180 - (atan2(item 2 of p3-item 2 of p2,item 1 of p3 - item 1 of p2)-atan2(item 2 of p2-item 2 of p1,item 1 of p2 - item 1 of p1))/pi*180





More information about the use-livecode mailing list