pi
pi
is a predefined variable that returns a
real
value of about 3.14159. You can use this
predefined variable in geometry calculations, as in the following
example. This script has a getArea subroutine
that returns the area of a circle when passed the
circle’s radius as an argument. Chapter 8 discusses how to create your own functions.
set circleArea to getArea(12) on getArea(radius) if (class of radius) is in {integer, real} then (* check to make sure parameter is a valid number *) return pi * (radius ^ 2) -- this calc returns the area of a circle else return 0 end if end getArea