Deriving an angle from three points

Jacques Hausser jacques.hausser at unil.ch
Wed Dec 16 03:58:00 EST 2009


As usual, I forgot something... Distance is merely this brave old Pythagora:

function Distance a,b
   ----------------------------------------------------------
   -- a,b : points
   -- returns distance (real) between a and b
   ----------------------------------------------------------
   return sqrt((item 1 of a - item 1 of b)^2 + (item 2 of a - item 2 of b)^2)
end distance

Jacques


Le 16 déc. 2009 à 09:47, Jacques Hausser a écrit :

>> 
>> On 12/15/09 10:21 PM, Mark Swindell wrote:
>>> 40,116
>>> 98,186
>>> 132,118
>>> 
>>> How would one determine the angle created from three points, such as those above?
> 
> Hi Mark,
> 
> I'm using the following handlers. SurfaceTriangle is used to determine if you compute the outer (>180) or inner angle with summit c in calcangle.
> 
> HTH
> 
> Jacques
> 
> function SurfaceTriangle a,c,b
>   ----------------------------------------------------------
>   -- a,c,b: points
>   -- returns twice the surface of triangle a,c,b
>   -- the result is signed, positive if points follow each other clockwise,
>   -- negative otherwise.
>   -- aligned points return zero.
>   ----------------------------------------------------------
>   put ((item 1 of c - item 1 of a)*(item 2 of b - item 2 of a)\
>   - (item 1 of b - item 1 of a)*(item 2 of c - item 2 of a)) into aire
>   return aire
> end SurfaceTriangle
> 
> function calcAngle a,c,b
>   ----------------------------------------------------------
>   -- a,c,b : points. 
>   -- returns angle between ca and cb in degrees
>   ----------------------------------------------------------
>   put Distance(c,b) into da
>   put Distance(a,c) into db
>   put Distance(a,b) into dc
>   put (da + db + dc)/2 into p
>   put sqrt(p*(p-dc)/(db*da)) into lecos
>   if lecos > 1 then put 1 into lecos
>   if lecos < -1 then put -1 into lecos
>   put acos(lecos) * 180 / pi into alpha
>   put 2 * alpha into alpha
>   if SurfaceTriangle(a,c,b) then
>      return alpha
>   else
>      return 360-alpha
>   end if
> end calcAngle
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

******************************************
Prof. Jacques Hausser
Department of Ecology and Evolution
Biophore / Sorge
University of Lausanne
CH 1015 Lausanne
please use my private address:
6 route de Burtigny
CH-1269 Bassins
tel/fax: 	++ 41 22 366 19 40
mobile:	++ 41 79 757 05 24
E-Mail:	jacques.hausser at unil.ch
*******************************************




More information about the use-livecode mailing list