Showing posts with label simulation. Show all posts
Showing posts with label simulation. Show all posts

Saturday, January 4, 2025

Projectile Motion Simulation and Animation

Projectile Motion Simulation – Complete Visual & Mathematical Guide

๐Ÿš€ Projectile Motion – From Physics to Animation

Imagine throwing a ball into the air… it rises, slows down, and falls back. That curved path is called projectile motion.

In this guide, you’ll not only understand the physics—but also how to simulate and animate it.


๐Ÿ“š Table of Contents


๐ŸŽฏ User Inputs

  • Initial Velocity \(u\) (m/s)
  • Angle \( \theta \) (degrees)
Example: u = 20 m/s, ฮธ = 45°

๐Ÿง  Core Physics Idea

Projectile motion is split into two independent parts:

  • Horizontal motion → constant speed
  • Vertical motion → affected by gravity

๐Ÿ“ Mathematical Formulas (Clearly Explained)

1. Convert Angle to Radians

\[ \theta_{rad} = \theta \times \frac{\pi}{180} \]

2. Velocity Components

\[ u_x = u \cdot \cos(\theta) \]

\[ u_y = u \cdot \sin(\theta) \]

๐Ÿ‘‰ Think of velocity being split into horizontal and vertical parts.

3. Time of Flight

\[ T = \frac{2u_y}{g} \]

Simple meaning: How long the object stays in air.

4. Position at Time t

\[ x(t) = u_x \cdot t \]

\[ y(t) = u_y \cdot t - \frac{1}{2}gt^2 \]

๐Ÿ‘‰ x increases steadily, ๐Ÿ‘‰ y rises then falls (because of gravity).

5. Maximum Height

\[ H = \frac{u_y^2}{2g} \]

6. Range

\[ R = u_x \cdot T \]


⚙️ Simulation Steps

  1. Divide total time into small steps
  2. Compute x and y for each step
  3. Store positions
  4. Animate movement

๐Ÿ’ป Code Example (Python)

import numpy as np u = 20 theta = np.radians(45) g = 9.8 ux = u * np.cos(theta) uy = u * np.sin(theta) T = (2 * uy) / g t = np.linspace(0, T, 50) x = ux * t y = uy * t - 0.5 * g * t**2 print("Range:", x[-1]) print("Max Height:", max(y))

๐Ÿ–ฅ️ CLI Output

Click to Expand
Range: 40.8 meters
Max Height: 10.2 meters

๐ŸŽฌ Visualization Logic

To animate:

  • Plot x vs y
  • Move a point frame-by-frame
  • Update position over time
This creates a smooth curved trajectory.

๐Ÿ’ก Key Takeaways

  • Projectile motion is predictable using physics
  • Horizontal and vertical motions are independent
  • Math formulas define the entire trajectory
  • Simulation = applying formulas step-by-step

๐ŸŽฏ Final Thought

Once you understand these equations, you can simulate everything from throwing a ball… to launching a rocket.

Wednesday, September 25, 2024

Queue Simulation with Enqueue and Dequeue Operations

You are tasked with simulating a simple queue management system. A queue is a data structure where elements are processed in a **First In, First Out (FIFO)** order, meaning that the first element added to the queue is the first one to be removed.

You need to process a series of commands where:
- **ENQUEUE** (or shorthand **E**) adds an element to the end of the queue.
- **DEQUEUE** (or shorthand **D**) removes the front element from the queue.

The program will take an integer input representing the number of commands, followed by a sequence of commands that either enqueue or dequeue elements from the queue. After processing all the commands, the program will output the remaining elements in the queue in the order they appear.

### Solution Breakdown:

1. **Queue Initialization:**
   - The queue is initialized as an empty structure. This is where elements will be added (via ENQUEUE) or removed (via DEQUEUE).

2. **Processing Commands:**
   - The program reads the total number of commands from the user.
   - It then iterates through each command:
     - If the command is **ENQUEUE** (or shorthand **E**), it appends the specified value to the end of the queue.
     - If the command is **DEQUEUE** (or shorthand **D**), it removes the element from the front of the queue, but only if the queue is not empty (to avoid errors).

3. **Final Output:**
   - After processing all the commands, the program prints out any remaining elements in the queue. These elements are printed in the same order they were enqueued but have not been dequeued.

### Example Walkthrough:
Given the input:


5
ENQUEUE 1
ENQUEUE 2
DEQUEUE
ENQUEUE 3
DEQUEUE


- First, two numbers (`1` and `2`) are enqueued.
- Then, the **DEQUEUE** command removes the first number (`1`), leaving `2` in the queue.
- Next, `3` is enqueued.
- Finally, another **DEQUEUE** removes the first element (`2`), leaving only `3` in the queue.

The final output will be:

3
 

This reflects the remaining element in the queue after processing all the commands.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts