Kinematic Analysis of 3D Motion

This Python script performs a fundamental kinematic analysis by evaluating the position, velocity, and acceleration of a particle moving through three-dimensional space. By defining these vectors as functions of time, the program can calculate not only their magnitudes but also their direction cosines, which describe the orientation of the motion relative to the X, Y, and Z axes.

Core Components

Vector Decomposition: The script breaks motion down into orthogonal i, j, and k components.

​Resultant Calculation: It computes the vector magnitude using the Pythagorean theorem in 3D.

​Angular Orientation: It determines the specific angles (α, β, γ) the vector makes with each primary axis.

Code 



import math

# Function to calculate the magnitude and direction angles of a 3D vector
def resulant_vec(bx, by, bz):
    # Magnitude: sqrt(x² + y² + z²)
    res = math.sqrt(bx**2 + by**2 + bz**2)
    
    # Direction Cosines: The angles the vector makes with the x, y, and z axes
    # Uses acos(component / magnitude) to find the angle in radians, then converts to degrees
    alpha = math.degrees(math.acos(bx / res)) % 360  # Angle with x-axis
    beta = math.degrees(math.acos(by / res)) % 360   # Angle with y-axis
    gamma = math.degrees(math.acos(bz / res)) % 360  # Angle with z-axis
    
    return res, alpha, beta, gamma

# --- Define Vector Components as Functions of Time (t) ---

# Position Vector: r(t) = 1.0i + 4t²j + tk
pos_vec = {
    "r": {
        "i": lambda t: 1.0,
        "j": lambda t: 4 * t**2,
        "k": lambda t: t
    }
}

# Velocity Vector: v(t) = dr/dt = 0i + (8t - 5)j + 1k
# Note: There is a constant -5.0 here not present in the position derivative
vel_vec = {
    "v": {
        "i": lambda t: 0, 
        "j": lambda t: 4 * 2.0 * t - 5.0, 
        "k": lambda t: 1
    }
}

# Acceleration Vector: a(t) = dv/dt = 0i + 8j + 0k
acc_vec = {
    "ac": {
        "i": lambda t: 0, 
        "j": lambda t: 8, 
        "k": lambda t: 0
    }
}

t = 2.0  # Evaluation time

# --- Processing Position ---
print("Position")
r_x = pos_vec["r"]["i"](t)
r_y = pos_vec["r"]["j"](t)
r_z = pos_vec["r"]["k"](t)
print(f"{r_x:.1f}i{r_y:+.1f}j{r_z:+.1f}k") # Formats output with signs

r_vec, r_alpha, r_beta, r_gamma = resulant_vec(r_x, r_y, r_z)
print(f"Magnitude:{r_vec:.2f}")
print(f"α:{r_alpha:.2f} deg")
print(f"β:{r_beta:.2f} deg")
print(f"γ:{r_gamma:.2f} deg")

# --- Processing Velocity ---
print("\nVelocity")
v_x = vel_vec["v"]["i"](t)
v_y = vel_vec["v"]["j"](t)
v_z = vel_vec["v"]["k"](t)
print(f"{v_x:.1f}i{v_y:+.1f}j{v_z:+.1f}k")

v_vec, v_alpha, v_beta, v_gamma = resulant_vec(v_x, v_y, v_z)
print(f"Magnitude:{v_vec:.2f}")
print(f"α:{v_alpha:.2f} deg")
print(f"β:{v_beta:.2f} deg")
print(f"γ:{v_gamma:.2f} deg")

# --- Processing Acceleration ---
print("\nAcceleration")
a_x = acc_vec["ac"]["i"](t)
a_y = acc_vec["ac"]["j"](t)
a_z = acc_vec["ac"]["k"](t)
print(f"{a_x:.1f}i{a_y:+.1f}j{a_z:+.1f}k")

a_vec, a_alpha, a_beta, a_gamma = resulant_vec(a_x, a_y, a_z)
print(f"Magnitude:{a_vec:.2f}")
print(f"α:{a_alpha:.2f} deg")
print(f"β:{a_beta:.2f} deg")
print(f"γ:{a_gamma:.2f} deg")

Comments

Popular posts from this blog

Carbonyl Sulphide COS

Applications of Elemental Properties

Dwarf Planets