 Math Commands Hexadecimal Numbers These numbers are prefixed by the "0x" character sequence, and can contain 1-8 hexidecimal digits (A-F, a-f, 0-9). ... t = 5 * 0xa0; // equivalent to 5 * 160 ... In addition, the integer() function has been enhanced to recognize and process hexidecimal numbers in string form. ... t = integer("0x0a"); // t will hold 10 t = integer("Now is the 0xF000 time"); // t will hold 61440 ... Scientific Notation The compiler now correctly recognizes and processes numeric values in scientific notation without the need for trailing decimal values. ... val = 2e2; ... This section describes the commands available to both Layout and Modeler LScripts. These include commands and functions for math, variable conversions, string manipulations. Binary Numbers LScript now provides support for binary-formatted numbers. These numbers are prefixed by the "0b" character sequence, and can contain 1-32 binary digits (0 or 1). ... t = 0b1001; // t holds 9 ... In addition, the integer() function has been enhanced to recognize and process binary numbers in string form. ... t = integer("0b110"); // t will hold 6 t = integer("Now is the 0b10000 time"); // t will hold 16 ... This section describes the commands available to both Layout and Modeler LScripts. These include commands and functions for math, variable conversions, string manipulations. General Commands center The center command returns the center point that lies between two given points in three-dimensional space. This command accepts a number of different parameter counts and types: an array whose first two elements are vectors, two vectors (either as a constant or as variables), or six numeric values where the first three represent the first vector, and the next three represent the second vector. center() returns a vector data type. // since boundingbox() returns two vectors, we can just // feed its output to center() objectCntr = center(boundingbox()); extent The extent command accepts the same number and types of arguments as center(), but instead of calculating the center of a pair of vectors, it returns the extents (distances) between the two points. extent() returns a vector data type, whose elements (x, y, z) represent the extents along each of those axes. objectSize = extent(boundingbox()); angle The angle function returns the angle, in degrees, between two points on a specified plane (XZ, YZ, or XY). It accepts two vectors representing the two points, and a third parameter that specifies the axis perpendicular to the plane in which the angle should be calculated. … editbegin();     pnt1 = pointinfo(points);     pnt2 = pointinfo(points); editend(); info(angle(pnt1,pnt2,X),“degrees”); // return angle in the                                                 // YZ plane … regexp The regexp() function lets LScript construct regular expressions from character strings. Use this function to enter regular expression patterns. regexp() can replace regular expressions if two separate arguments are provided for compiling. // display lines in a file that begin with the letters “PUB” // compile a regular expression to be used expr = regexp(“^PUB”); // regexp() returns ‘nil’ if the expression fails to compile if(expr == nil)     return; if((file = File(“nfa.c”,”r”)) == nil)     return; while(!file.eof()) {     line = file.read();     if(line == expr)         info(line); } Conversions The conversion commands convert variables of one type to another. Several of these commands have method equivalents. `The conversion functions integer(), number() and vector() can scan a provided character string until they find the first numeric occurrence (a number or a period [.] followed by a number) before they attempt to convert. x = integer("My number: 55"); // returns 55 x = number("fskd#jdl.532(iew"); // returns .532` number number() takes a string argument and attempts to convert it into a numeric(floating-point) value. str = “69.6”; t = number(str);// returns 69.9 t = number(“The answer is: .1593”); // returns .1593 binary A binary() function is now available that will convert integer values into their binary equivalents in string form. The function takes an integer value, and an optional size value (whose maximum on any platform is [sizeof(int) * 8] bits). The function will remove leading zeros, unless an explict number of bits are indicated: generic {     info(binary(32)); // displays "100000"     info(binary(32,32)); // displays "00000000000000000000000000100000"     info(binary(130,8)); // displays "10000010"     info(binary(130,10)); // displays "0010000010" } integer integer() takes a string argument and returns an integer value. If the character string includes a decimal point, it will be stripped. str = “69.6”; t = integer(str);            // returns 69 t = integer(round(number(“69.9”))); // returns 70 vector The vector command takes a string argument and attempts to convert it into a vector. str = “4 6.5 8”; t = vector(str); // returns <4,6.5,8> string The string() command takes a varying number of arguments, each of which can be any of the supported LScript data types (except array), and constructs a character string. t = string(“Value “,val,” exceeds max limit of “, 10 * items,” items”); ascii The ascii() conversion function takes a character value and returns its integer equivalent. This is handy for comparing nonprinting characters. if(ascii(line[x]) == ‘\t’) hex The hex conversion tool converts a number into a hexadecimal value. obj = getfirstitem(LIGHT); info(hex(obj.id));     // prints “0x20000000” octal The octal conversion tool converts a number into its octal value. value = octal(1.7);//result: “\1” Math sqrt The sqrt() function calculates the square root of a number. It accepts a numeric value, and returns the square root of that value. value = sqrt(4); //result: 2 exp The exp() function calculates the exponent of a value. It accepts a numeric value, and returns the exponent of that value. value = exp(2); //result: 7.38906 log The log() function calculates the logarithmic value of a number. It accepts a number, and returns the logarithmic value of that number. value = log(124.2); //result: 4.82189 log10 The log() function calculates the logarithmic base 10 value of a number. It accepts a number, and returns the logarithmic value of that number. sin The sin() function calculates the sine value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = sin(241.8); //result: 0.102454 cos The cos() function calculates the cosine value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = cos(153.2); //result: -0.739789 tan The tan() function calculates the tangent value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = tan(135.0); //result: -0.0887158 asin The asin() function calculates the asin value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = asin(.2); //result: 0.201358 acos The acos() function calculates the acos value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = acos(.53); //result: 1.0122 atan The atan() function calculates the atan value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = atan(129.2); //result: 1.56306 cosh The cosh() function calculates the hyperbolic values of the cos() function. value = cosh(82.2); //result: 1.55863 sinh The sinh() function calculates the hyperbolic values of the sin() function. value = sinh(.13); //result: 0.130366 tanh The tanh() function calculates the hyperbolic values of the tan() function. value = tanh(.01); //result: 0.00999967 cot The cot() function calculates the cot value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = cot(21); //result: -0.654665 csc The csc() function calculates the csc value of an angle, specified in radians. It accepts a numeric radian angle, and returns the operation result of that value. value = csc(121.3); //result: 1.06403 abs The abs() function returns the absolute value of a number. Regardless of the sign of the number, the return value from this function is always positive. value = abs(-121.2); //result: 121.2 ceil The ceil() function returns the smallest integer value that is greater than or equal to the numeric value passed as an argument. value = ceil(-1.201); //result: -1 floor The floor() function returns the largest integer value that is less than or equal to its numeric parameter. value = floor(-1.201); //result: -2 deg The deg() function accepts a single numeric angle parameter, specified in radians, and converts it to degrees. value = deg(241.3); //result: 13824.5 random The random() function generates pseudo-random integer numbers. It can either accept two numeric integer values—which returns a random integer number that lies between those two numbers (inclusive)—or it can accept two floating-point numbers— which will generate a floating-point number that lies between those numbers. Numbers can be negative or positive. triggerFrameInt = random(20,50); triggerFrameFloat = random(20.2, 50.2); min The min() function returns the smaller of its two numeric arguments. t = min(1,7); //result: 1 max The max() function returns the larger of its two numeric arguments. t = max(1,7); //result: 7 mod The mod() function returns the modulo—or remainder—of the division when its first numeric argument is divided by its second. The LScript operator % can also be used as a substitute for this behavior. t = mod(34.5,6); // returns 4.5     or, alternately, t = 34.5 % 6; pow The pow() function raises its first numeric argument to the power specified by the second argument. You can also use the ^^ operator t = pow(5,3); // returns 125 or t = 5^^3; hypot The hypot() function calculates the hypotenuse of the right triangle whose sides correspond to the function’s first and second numeric arguments. t = hypot(3,5); rad The rad() function accepts a single numeric angle parameter, specified in degrees, and converts it to radians. t = rad(degrees); // equivalent to: degrees * (PI / 180) randu The randu() function returns a random number that lies between 0 and 1. rad = 0.05 * maxlen * (1 + randu()); range The range() function determines if its first numeric parameter falls within the range of numeric values specified by the second and third parameters, inclusively. It returns a Boolean value (true or false). if(range(top,3,8)) selector The selector() function compares the first two numeric parameters, and if the first is less than the second, it returns the third. If the first is greater than or equal to the second, it returns the fourth. t = selector(4,7,15,3); // returns 15 t = selector(15,7,7,10); // returns 10 step The step() function evaluates two numeric arguments, and if the second value is less than the first, it returns 0 . If the second value is greater than or equal to the first, it returns the third numeric parameter . t += step(y,10,.25); // step by .25 round The round() function will round a numeric value to the decimal place specified in the second integer parameter. If this second value is 0, then the numeric value will be rounded to the nearest whole integer. t = round(37.7,0); // returns 38 t = round(4.4394,2); // returns 4.44 frac The frac() function returns the fraction portion of a numeric value. t = frac(46.75); // returns 0.75 fac The fac() command calculates the factorial value of the provided numeric parameter. t = fac(5); // returns 120 Vector Commands vmag The vmag() function calculates the magnitude of a three dimensional vector. It can take a vector or three numeric values.  t = vmag(x,y,z); // calculate magnitude of my location You can calculate the distance between two arbitrary vectors in space simply by subtracting them and passing the result to vmag(): v1 = <1,3,5.4>; v2 = <.054,2,90>; t = vmag(v1 - v2); cross2d cross2d() calculates the cross product of two floating-point values. value = cross2d(21.4, 53.2, 34.2, 12.1); //result: -1560.5 cross3d cross3d() calculates the cross product of two 3-D vectors. a = <13.2, 2.5, 5.2>; b = <122.1, 23.4, 53.2>; value = cross3d(a,b); //result: <11.32, -67.32, 3.63> … dot2d dot2d() calculates the dot product of two floating-point values. value = dot2d(112.1, 24.8, 63.3, -125.6); //result:10210.8 dot3d dot3d() calculates the dot product of two 3-D vectors. value = dot3d(<12.2, 42.5, -12.3>, <125.5, 32.6, -23.1>); //result: 3200.73 sec The sec() function calculates the secant value. value = sec(123.3); //result: -1.40371 gamma The gamma() function interpolates the factorial function of a value. value = gamma(121.7); //result: 121.7 normalize The normalize() function takes a vector and returns a normalized version of that vector. vec = 123.2; vec = normalize(vec); //result: <0.992815, -0.0257874, 0.116849> … 