Monday, 6 January 2025

Tech Art Math Part 1

 Algebra, Geometry, Trigonometry

Slopes: tell us going from left to right or are you going up or down. Zero slope (horizontal) and Undefined slope (vertical).

Slope is Rise Over Run, (y2-y1)/(x2-x1).

Right Triangles: Types include Scalene (no sides are the same) and Isosceles (Two Equal sides at 45 degrees). Length of Hypotenuse calculated with the Pythagorean Theorem.

Sine, Cosine, and Tangent are definitions given to ratios of similar triangles. Remember SOHCAHTOA (Sine Opposite Hypotenuse, Cosine Adjacent Hypotenuse, Tangent Opposite Adjacent). 

Cosine helps to measure the x distance. Tangent is the pure ratio between the angles, when you don't know the hypotenuse.

Asin, Acos, and Atan is used when you know the ratio but don't know the θ angle instead. 

Unit Circles

    Unit circles are circles with a radius of 1, or a diameter of 2.

    Circumference = 2 * Radius * pi

    Area = pi * Radius * Radius

    Radian: unit of angle in the International System of Units (SI). An abstract amount. A dimensionless SI derived unit. 

    If you took the radius of a circle, and then shrink wrapped it to the surface of the circle, that would be 1 Radian. 180 degrees = pi radians. 360 degrees = 2pi radians.

    1 degree = 2pi radians / 360 degrees or 1 = pi radians / 180

    1 radian = 360 degrees / 2 pi Radians or 1 = 360 degrees / pi

    A lot of math libraries assume you work in radians.  

Circular Functions

sin θ = Y Component

cos θ = X Component

Remember Law of SIN: 

sin^2 θ + cos^2 θ = 1



Law of COS: a^2 = b^2 +c^2 - 2bc cos θ

If you don't have a right triangle you can use the Law of Signs

sin α / a = sin β / b = sin θ / c


Vectors

    A vector: one-dimensional Array representing the solution of a system of linear equations. An element of the real Coordinate Space Rn (a coordinate in space, like xyz). Vectors can be multidimensional (but that dimension should be defined). All vectors originate from the origin (although you can offset them to move them around).
    They represent positions in space (a point, but this will have a direction of 0).
    Colors are vectors. 
    Notations

Why is w at the end of the 4x1 or 1x4 vector? w is the Homogenous Coordinate. It defines if the vector is a direction (0)(think of it as the default) or a point in space (1). It helps to make the math work. In tech art, most of the time you'll be working with 4x1 or 1x4 matrices. 

Vector Operations

Vector Addition:

    You add corresponding components.  


     When you add two vectors, shouldn't the resulting vector be on top of the other? Technically it is, but since all vectors originate at the origin, the tail of the new vector comes from the origin.

Vector Subtraction

    Similar to vector addition, you subtract corresponding components. 

    For A-B Think 'what vector would I need to add to B to get to A.

Scalar Multiplication

    Multiply all the components of the vector by the scalar (a constant number)

Length (or Magnitude)

    Use the Pythagorean theorem to calculate the length. 
    Add up all the squares of the vector components then square root it. 
    The Pythagorean theorem does not work on points. The length of a point will always be zero. 

Normalizing

    Normalizing a vector makes it a unit vector. A unit vector is a vector with a length of 1. This makes it easy to use in calculations, as it only shows direction. Calculate the length of a vector, then divide each component by the length.
    Scalar has the length, D has the direction. Put a bar over the direction to show that it is a unit vector

Dot Product

    The Dot Product is the Sum of products of matching components. Produces a scalar value known as Scalar Product or Inner Product. Always a floating point value. 
    You can use it to find the angle between vectors, or to project one vector onto another. It is communitive, distributive, and associative. 

Vector Triangle Inequality

If you add two vectors and take the magnitude of them, it will always be less than or equal to the magnitude of two vectors added together.

Angle Between Vectors

Taken from the law of cosines

    If a and b are unit vectors, then their dot product is equal to the cosine of the angle between them (since their magnitudes are just 1, 1 times anything is itself. 
You will be seeing left handed and right handed coordinate space, depending on which one it is will determine which way vectors are pointing. 

Cross Product

    Performing the cross product between two vectors will produce a vector that is perpendicular to them. 

Matrices


     An ‘N’-Dimensional array of Numbers. Most typically N = 2
    Each "Straight Line" of a Matrix can be considered as "one" vector. Each column is a unique vector. Each row is a unique vector.
 

    Typically 'M' Rows and 'N' Columns. Described as a M x N matrix

Scalar Multiplication

    Each entry in Matrix multiplied against scalar

Addition and Subtraction

    Must have same number of rows and columns, else it is undefined. You will add or subtract corresponding components. (Similar to vector addition and subtraction). Addition is commutative, but subtraction is not. 

Transpose

    Rows become Columns and Columns become Rows
    What once was row vectors, have now become column vectors. 

Multiplication

    Take the Dot Product of rows and columns to produce components of corresponding matrix. This is associative but not commutative

    
The number of columns of the 1st matrix must equal the number of rows of the 2nd matrix
And the result will have the same number of rows as the 1st matrix, and the same number of columns as the 2nd matrix.

    Think if you have a 3x2 matric multiplied with a 2x3 matrix, you'll get a 3x3 matrix. (Think the inside values need to be the same, and the result will inherit the outside values)
3x2 * 2x3 = 3x3
1x3 * 3x5 = 1x5

Identity matrix

    Is there a matrix in that if we multiply anything it will equal itself. Yes the Identity matrix. The dimension of Identity is always square. 

Zero Matrix

    Any zero packed matrix which is defined to multiply against A. Just a matrix will full zeros. 

Matrix Inversion

    Is there an inversed matrix that when multiplied with it's original matrix will produce the identity matrix. 


    In order to get the inverse, the matrix has to be a square matrix. You'll also need the determinant. 
A determinant is a scalar-valued function to represent a matrix (like a magnitude for a vector)

No comments:

Post a Comment

Shader Tool Week 3 - Surface Mapping

 Texture Cubes     Also known as cube maps, its 6 2D texture maps corresponding to the faces of an axis-aligned cube. Used in lighting a sce...