Normal Vector and Other Math

Distance Traveled Under Acceleration

Finds the distance traveled (d) of an object with an initial velocity of zero, acceleration (a), and time (t) traveled. The equation used is

d = ½ * a * t2

Finds the distance traveled (d) of an object with an initial velocity (v), acceleration (a), and time (t) traveled. The equation used is

d = (v * t) + (½ * a * t2)

2D Normal Vector

2D Rotation: To find the normal to a 2D vector (x,y), rotate it by 90 degrees to get (-y,x).

From Two Points (x0,y0) and (x1,y1): Find the direction vector (x1-x0,y1-y0). The normal vector is obtained by swapping components and changing one sign: n = (-(y1-y0),x1-x0).

Unit Normal Vector: To get a normal vector with a length of 1, divide the normal vector by its magnitude: u = n/|n|. (|n| is the absolute value of n)

Turn a Line Segment Into a Vector

From Two Points (x0,y0) and (x1,y1): Find the direction vector (x1-x0,y1-y0).

Turn a Vector Into a Unit Vector

Calculate the Magnitude (Length): Calculate the magnitude |v| of the vector v = (x,y,z) using the formula: |v| = math.sqrt(x2+y2+z2). Divide each component of the vector by the calculated magnitude: u = (x/|v|, y/|v|, z/|v|)

Note: For 2D don't do the Z part.

# ========================================================= # verify/test: turning a vector into a unit vector # # Note: This code cannot be used on a zero vector (0,0,0) # Division by zero is undefine. # ========================================================= import math # ---- know vector v = (2,2,1) magnitude = 3 x = 2.0 y = 2.0 z = 1.0 ##x = 2.0 ##y = 2.0 ##z = 2.0 ##x = 100.0 ##y = 200.0 ##z = 300.0 print(f'v = ({x},{y},{z})') v_mag = math.sqrt(x**2 + y**2 + z**2) print(f'v magnitude = {v_mag}') print() # ---- unit vector calculation print('u = '+\ f'({(x/v_mag):.4f},{(y/v_mag):.4f},{(z/v_mag):.4f})') u_x = (x/v_mag)**2 u_y = (y/v_mag)**2 u_z = (z/v_mag)**2 u_mag = math.sqrt(u_x + u_y + u_z) print(f'u magnitude = {u_mag}') print()

Miscellaneous Other Links

Question: What is MonoGame? What is Godot? What is the difference?