Deriving an angle from three points
gmccarthy
gmccarthy at people.net.au
Wed Dec 16 05:07:46 EST 2009
By the way again, Mark's method is also correct if you fix the variable names
as shown below.
Normally a triangle with points ABC have their sides named with side b
between A and C so it is opposite angle B...etc.
on mouseUp
put cd fld "A" into pointA
put cd fld "B" into pointB -- assumed center of angle
put cd fld "C" into pointC
--
-- get the lengths of the three sides of the triangle
put SideLength(pointA, pointB) into lengthC
put SideLength(pointB, pointC) into lengthA
put SideLength(pointA, pointC) into lengthB
--calculate the angle as arccos( (b2+c2-a2) / 2bc)
--the other two angles are arccos( (a2+c2-b2) / 2ac)
-- and arccos( (a2+b2-c2) / 2ab)
put (lengthA * lengthA) + (lengthC * lengthC) - (lengthB * lengthB) into
tSub
put acos(tSub / (2 * lengthA * lengthC)) into tRadians
put (tRadians * 180 / pi) into cd fld "AngleABC"-- convert from radians
to degrees
end mouseUp
-- calculate (x2-x1)^2 + (y2-y1)^2
-- return the square root of that
function SideLength pPointA, pPointB
local lengthX, lengthY
set the itemdelimiter to comma
put item 1 of pPointB - item 1 of pPointA into lengthX
put lengthX * lengthX into lengthX -- x squared
put item 2 of pPointB - item 2 of pPointA into lengthY
put lengthY * lengthY into lengthY -- y squared
return sqrt(lengthX + lengthY) -- length of hypotenuse
end SideLength
--
View this message in context: http://n4.nabble.com/Deriving-an-angle-from-three-points-tp964930p965059.html
Sent from the Revolution - User mailing list archive at Nabble.com.
More information about the use-livecode
mailing list