Skip to content

Elastic collisions of Spheres using Ebiten game library.

License

Notifications You must be signed in to change notification settings

alexdesi/collisions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collisions

Collisions is a simple elastic collisions simulator of two spheres in a 2D space.

It calculates the velocities and directions of the spheres after collisions, using linear algebra and avoiding the use of complex trigonometry.

Elastic collisions of two spheres in Go

The vector operations needed to calculate the elastic collision are simply outlined in the doc 2-Dimensional Elastic Collisions without Trigonometry written by @vobarian.

I have not imported any external library for the vector operations, I wrote vectors.go with few basic functions.

Collisions is made of four packages:

  • wren: it contains the core function to calculate the speed of the spheres after the impact.
  • detector: it contains the functions to detect the collision of the sphere, with each other, or with the edges.
  • shapes2D: it contains the function to draw the circles (the spheres).
  • vectors: it contains the basic functions to work with vectors.

How did you animated the spheres?

I used Ebiten - a simple graphics library to build games in Go.

How to run Collisions?

go run main.go

Why did you write Collisions?

A while ago I wrote something similar in Java, but I wasn't happy with the result and I did not share it.

Now, I am learning Go, and I decided to resume that old idea to write my Hello Word in Go.

What's next?

Some ideas are:

  • Use any number of spheres
  • Add friction
  • Add gravity
  • Add inelastic collision
  • ...

Feel free to clone this project and expand it at your whish.


Alessandro De Simone

About

Elastic collisions of Spheres using Ebiten game library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages