--@ Version 2.0.1 --@ Author Luke --@ Created 2001-1-23 --@ Description -- Some maths functions, implemented as movie script functions. --@Notes --The Trig functions will return VOID if the input --is invalid for that function. -- --Also, note, as a maths guru, I am a good opera singer. Apoligies --if any of these functions are wrong. If they are, please let me --know - luke at meccamedialight-com-au ---------------------------------------------------------------- on sec (x) tmp = cos(x) if tmp <> 0 then return 1.0/tmp else return VOID end on cosec (x) tmp = sin(x) if tmp <> 0 then return 1.0/tmp else return VOID end on cot (x) tmp = tan(x) if tmp <> 0 then return 1.0/tmp else return VOID end -- Inverse functions on arcSin (x) -- returns values between -pi/2 and pi/2 -- returns VOID if abs(x) > 1 aX = abs(x) if aX < 1 then return atan(float(x)/sqrt(1-x*x)) else if aX = 1 then return x*pi()/2 else return VOID end on arcCos (x) -- Returns values between 0 and pi -- Input "x" must be between -1 and 1 if abs(x) > 1 then return void else return pi()/2-arcSin(x) end on arcTan (x, y) -- This is a RTFM function (doh!) if the paramCount = 2 then return aTan(y,x) -- undoc'd else return aTan (x) end -- hyperbolic functions on sinh (x) return (exp(x) - exp(-x))/2 end on cosh (x) return (exp(x) + exp(-x))/2 end on tanh (x) tmp = cosh(x) if tmp <> 0 then return sinh(x)/tmp else return VOID end -- More trig on versine (x) z = x/2.0 return 2 * sin(z*z) end ---------------------------------------------------------------- -- Numbers ---------------------------------------------------------------- on floor (x) -- floor moves left on the number line (negative numbers are -- 'floored' away from 0). intX = bitOr( x, 0 ) if( x = intX ) then return intX else if( x > 0 ) then return intX else return intX - 1 end on ceil (x) -- Ceil moves right on the number line intX = bitOr( x, 0 ) if( x = intX ) then return intX else if( x > 0 ) then return intX + 1 else return intX end on trunc (x) -- trunc moves towards 0 return bitOr( x, 0 ) end on fix (x) -- (alias of trunc) -- Returns an integer (rounds towards 0) return bitOr( x, 0 ) end on round (x) -- round to nearest integer return integer(x) end on roundup (x) -- returns an integer (rounds away 0) intX = bitOr( x, 0 ) if( x = intX ) then return intX else if( x > 0 ) then return intX + 1 else return intX - 1 end on sign (x) -- returns the sign (1, -1, 0) if x > 0 then return 1 else if x < 0 then return -1 else return 0 end on radsToDegrees (rads) -- sprite.rotation uses degrees. Lingo's math -- functions use rads! return rads*180.0/pi() end on degreesToRads (degrees) -- sprite.rotation uses degrees. Lingo's math -- functions use rads! return degrees*(pi()/180.0) end on isReal (x) return ( x <> x+1 ) end on isNormal (x) if x <> 0 then return ( x <> x+1 ) else return 0 end if end on isNaN (x) return ( string(x) contains "NAN" ) end on isINF (x) return ( string(x) contains "INF" ) end ---------------------------------------------------------------- -- Bit Shifting ---------------------------------------------------------------- on BitShiftLeft (x,n) -- x << n return x*power(2,n) end on BitShiftRight (x,n) -- x >> n return bitOr( x/power(2,n), 0) end ---------------------------------------------------------------- -- Various Helpful Functions ---------------------------------------------------------------- on GetGausseRandom (mean, standardDeviation) -- returns a standard Gaussian random number -- based upon the polar form of the Box-Muller transform w = 2.0 repeat while ( w >= 1.0 ) x1 = 2.0 * (random(0,1000000)/1000000.0) - 1.0 x2 = 2.0 * (random(0,1000000)/1000000.0) - 1.0 w = x1 * x1 + x2 * x2 end repeat w = sqrt( (-2.0 * log( w ) ) / w ) r = (x1 * w) if voidP(mean) then return r return (mean + r * standardDeviation) end