Skip to content

sdepl/CSCI596_FinalProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSCI596_FinalProject

Interactive Colliding Particle System Simulator

Compiling

To compile particle-collision.c, type: cc -o particle-collision particle-collision.c -L/System/Library/Frameworks -framework GLUT -framework OpenGL -lm

To run particle-collision.c, type: ./particle-collision

Assumptions

  • All particles are equal in size and mass

Collisions

Wall Collisions

A particle that lives in a region, $R = \begin{bmatrix} R_x \\ R_y \\ R_z \end{bmatrix}, $ has a position, $s = \begin{bmatrix} x \\ y \\ z\end{bmatrix}$ and a velocity of $v = \begin{bmatrix} v_x \\ v_y \\ v_z\end{bmatrix}$

When
$0 \geq x \geq R_x$ or
$0 \geq y \geq R_y$ or
$0 \geq z \geq R_z$
a wall collision has occurred.

If $0 \geq x \geq R_x$ then $v_x = -1 * D * v_x$
If $0 \geq y \geq R_y$ then $v_y = -1 * D * v_y$
If $0 \geq z \geq R_z$ then $v_z = -1 * D * v_z$
Where D is the damping coefficient if one exists

Particle Collisions

Particle A has a position, $s_A = \begin{bmatrix} x_1 \\ y_1 \\ z_1\end{bmatrix}$ and velocity $\vec{v_A} = \begin{bmatrix} v_x1 \\ v_y1 \\ v_z1\end{bmatrix}$
Particle B has a position, $s_B = \begin{bmatrix} x_2 \\ y_2 \\ z_2\end{bmatrix}$ and velocity $\vec{v_B} = \begin{bmatrix} v_x2 \\ v_y2 \\ v_z2\end{bmatrix}$
Both particles have radius r.

Find the distance between the two particles: $$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}$$

If $d < 2*r$, a collision between two particles has occurred.

Now new velocity vectors need to be calculated.

  1. Find the normal vector between the two particles: $\vec{N} = s_A - s_B $
  2. Get the magnitude of the normal vector by taking the square root of the dot product of the normal vector with itself: $||N|| = \sqrt {\vec{N} \cdot \vec{N}}$
  3. Divide the normal vector by its magnitude to get the unit norm vector: $\vec{n} = \frac{\vec{N}}{||N||}$
  4. Get the relative velocity between the two particles: $\vec{V} = v_A - v_B$
  5. Find the dot product of the unit norm vector and the relative velocity vector: $vn = \vec{V} \cdot \vec{n}$
  6. Multiply the resulting dot product with the unit norm vector: $\vec{VN} = vn * \vec{n}$
  7. Find the resulting velocities for each particle:
    • $v_A = (\vec{v_A} - \vec{VN}) * collisionDamping $
    • $v_B = (\vec{v_B} + \vec{VN}) * collisionDamping $

image

Usage

Interactive options:

  • You can grab and throw a particle with the mouse
  • 'g' increases upward gravity
  • 'h' increases downward gravity
  • 'z' increases size of particles
  • 'x' decreases size of particles
  • 'c' add particle to the system
  • 'v' remove particle from system
  • 'q' quit program
  • 'l' pan camera view clockwise
  • 'k' pan camera view counter-clockwise
  • 'd' decrease damping coefficient
  • 'f' increase damping coefficient
  • 'm' toggle on/off mapping the particle velocity to 3D color cube

Rotate View:

rotating

Click and Drag Particle:

drag_particle

Increase/Decrease Gravity:

gravity_down gravity_up

Add Particles:

add_particles

Remove/Add Particles:

rm_particles rm_particles (1)

Size Change:

size_change size_change (1) size_change (2)

Damping Coefficient Greater Than One:

damping_coeeff_gt1

About

color-code-atoms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages