-
Notifications
You must be signed in to change notification settings - Fork 0
Section 1: Math
in pryttier.math
This function takes an expression expr , repeats it from n to i and sums all the iteration, it is similar to:
The reason why expr parameter is of type Callable is because it is a function that takes the current iteration into
account
Examples:
summation(0, 5, lambda n: 1)is the same as:
and
summation(0, 5, lambda n: n + 1)is the same as:
This function is similar to the summation but instead of adding, it multiplies the iterations, It is similar to:
Example:
product(0, 3, lambda n: 2)is the same as:
and
product(0, 5, lambda n: 2
n)is the same as:
This function takes in a number num and returns it if it is in a given range from low to high (both inclusive).
if the number is below the range, it will return low and if the number is above the range, it will return high.
Example:
clamp(2, 0, 5) # This will return 2 itself because it is in the range from 0 to 5.
clamp(-1, 0, 5) # This will return 0 (which is `low`) as -1 is smaller than 0 and not in the range from 0 to 5.
clamp(10, 0, 5) # This will return 5 (which is `high`) as 10 is greater than 5 and not in the range from 0 to 5.This function will simply return the sign of the given number num
Example:
sign(-5) # Will return -1, representing negative sign
sign(7) # Will return 1, representing positive signThis function returns the factorial of a given number num.
Example:
factorial(5)is the same as:
This function converts a binary (Base 2) number to decimal
Example:
binToDec(101) # Will return 5
binToDec(10001) # Will return 17
binToDec(101101) # Will return 45This function takes a given number value in a range from min1 to max1 and converts it into a number in the
range min2 from max2
It maps a value from one range to another
For example: 5 in range 0 to 10, when mapped to range 0 to 100, will be 50
Examples:
mapRange(5, 0, 10, 0, 100) # Will output 50This is a Vector2 class having x and y values as inputs.
You can add, subtract, and multiply Vectors.
Example:
Vector2(5, 1)The Vector3 class is similar to Vector2 but with an additional z input and has the same operations as Vector2.
Example:
Vector3(4, 5, 3)This function takes in two vectors (Vector2 or Vector3 but not both at the same time) and cross multiplies them.
cross(Vector2(5, 5), Vector2(1, 2)) # will return -2
cross(Vector3(1, 2, 3), Vector3(2, 3, 4)) # will return Vector3(-1, 2, -1)
cross(Vector2(5, 5), Vector3(4, 5, 2)) # will give an error because cannot multiply Vector2 with Vector3This function returns the distance between two vectors
Example:
distance(Vector2(1, 2), Vector2(5, 2)) # Will return 4
distance(Vector2(2, 3), Vector2(4, 3)) # Will return 2
distance(Vector2(7, 8), Vector2(0, 0)) # Will return 10.63014581273465