-
Notifications
You must be signed in to change notification settings - Fork 3
Math
GlowScript help with math functions
Enter an integer (positive, negative, or zero) or a decimal number. Fractions cannot be entered in this block.
Click the operator sign to select different options:
- + (add)
- - (subtract)
- * (multiply)
- / (divide)
- ^ (exponent)
To combine more than two numbers in an arithmetic operation, multiple operation blocks must be assembled.
Example:
This compound block represents the compound operation 4 * (2 + 3)
, which is equal to 4 * 5
, or 20
. The inner block is computed first, just as though the operation were enclosed in parentheses.
The available operations in the menu will change according to the inputs that have been entered. The most efficient way (i.e., least number of mouse actions) to assemble an arithmetical operation involving one or more vectors is to first enter the inputs, and then select the operation.
The following operations are mathematically valid.
- number + number (returns a number)
- number - number (returns a number)
- number * number (returns a number)
- number / number (returns a number)
- number ^ number (returns a number)
- vector + vector (returns a vector)
- vector - vector (returns a vector)
- vector * number (returns a vector)
- number * vector (returns a vector)
- vector / number (returns a vector)
If the user attempts any of the following invalid mathematical operations, the operations available in the block menu will change according to the inputs that have been entered. For example, if the user attempts to divide a number by a vector, the vector will be accepted, but the divide symbol will be changed to multiply, which is valid.
- anything / vector
- anything ^ vector
- vector * vector
- vector + number (or vice versa)
- vector - number (or vice versa)
This block outputs a quantity that is the additive inverse, or "opposite", of the input argument. The input may be a vector or a number. The block includes a "shadow block" with a 1 in it because a program with the negative sign without a number to follow it would result in an error.
When the negative block takes a vector as an input, the result is also a vector (as indicated by the change in color of the negative block from turquoise to blue). The new vector is equal in magnitude to the original, but exactly opposite in direction.
This block performs the modulo operation between two numbers, producing the remainder when one number is divided by another. For example, 11 / 4 is 2 with a remainder of 3, so the block shown below would output 3.
The square root block returns the square root of any non-negative (zero or positive) number.
The absolute block returns the absolute value of any number.
This block outputs a quantity that is the additive inverse, or "opposite", of the input argument. The input may be a vector or a number.
The ln block returns the natural logarithm of a non-negative (zero or positive) number.
The log10 returns the base ten logarithm, or common logarithm of a non-negative (zero or positive) number.
The e^ block takes any number as input and returns the mathematical constant e raised to the power of the input number.
The ! block returns the factorial of the input number. The input must be a non-negative integer (i.e., 0, 1, 2, 3...)
The 10^ block takes any number as input and returns 10 raised to the power of the input number.
The trigonometric functions block returns the sin, cos, tan, asin, acos, atan of any number. The functions asin, acos, and atan are inverse trigonometric functions. In the case of sin, cos, or tan, the input number is assumed to be in radians. In the case of asin, acos, or atan, the output number is in radians.
The radians block takes a number of degrees as input and returns the equivalent number of radians. The menu inside the block can be changed to degrees, in which case the block takes a number of radians as input and returns the equivalent number of degrees.
The special constant block provides quick access to commonly-used special mathematical constants: pi, e, phi, square root of 2, and square root of one half.
The random fraction block generates a random decimal number between 0 and 1.
The math logic block evaluates the truth of the mathematical statement that is constructed and returns a Boolean True
or False
. The user inputs a number on the left and selects a condition using the pull-down menu on the right.
The round block takes a number as input and rounds it, returning the rounded number. The user can select round, round up, or round down using the block menu. If round is selected, the number will be rounded to the nearest integer.