Constrain Within Circle?

Joel Guillod joel.guillod at net2000.ch
Sat Nov 5 10:42:44 EST 2005


Should the ArcadeEngine be optimized for speed from ...


> Function findAngle
>    ...
>
>    put abs(x1-x2) into oppositeLeg
>    put abs(y1-y2) into adjacentLeg
>    if adjacentLeg<>0 then
>      put atan(oppositeleg/adjacentLeg) into alpha
>      put alpha*180/pi into alpha
>    else
>      put 90 into alpha
>    end if
>    switch
>    case x1<=x2 and y1>=y2
>      put alpha into foundAngle
>      break
>    case x1<=x2 and y1<=y2
>      put 180-alpha into foundAngle
>      break
>    case x1>=x2 and y1<=y2
>      put 180+alpha into foundAngle
>      break
>    case x1>=x2 and y1>=y2
>      put 360-alpha into foundAngle
>      break
>    end switch
>    return round(foundangle)
> end findAngle
>


...to :

Function geometry_findAngle
   ...
   put x1-x2 into oppositeLeg
   put y1-y2 into adjacentLeg
   return atan2(adjacentLeg,oppositeleg)*180/pi+90 -- +90 should be  
+180 in standard geometry
end geometry_findAngle

?

Well, this is just a suggestion. For speed and time sparing  
Revolution is so fast that my solution would probably spare only a  
fraction of millisec but may be my suggestion could help in code  
simplicity (3 lines against 23) and therefore maintenance and bytes  
size, isn't it?






More information about the use-livecode mailing list