Home

Golf Simulator -- Particle collision with functions

Goals for This project

The goal of this project was to create a golf simulator using particle physics from A5 and L8 to have the ball bounce on any surface.


In order to get this working, the collision detection, collision handling, and applied forces needed to be changed.


The golf "courses" were all defined as some function y = f(x,z). As long as there is a derivative for df/dx and df/dz exist the code can run any "course".


Building Blocks

Collision response

The first functionality that needed to be implemented was the ability for the ball to bounce. In order for the ball to bounce the velocity must be reflected around the surface normal using the following formula:


x = velocity vector & u = surface normal.


Additionally the normal (slope) is computed by the cross product between df/dx and df/dz.

This was the first course that was designed to test that the bouncing was working correctly by creating a uniform steep slope that was easy to calculate

In this case:

As shown above, since the derivative doesn't change, the slope is constant and the normal could be hard coded

Applying forces

This was the next course was designed to test the forces. By creating a bowl like shape I could test without the ball going off the course and could visualize the force better. It also allowed me to test the code with a more complex normal that varied on location

In this case:

Here I was able to test the damping coefficients, which determine how much velocity is lost after each bounce.
EX: Sand and water have lower coefficients because more velcity is lost.

I also used this course to test the force of wind which was randomly generated to make the ball's flight path change each time the simulation is run.

Additional functionalities

There are a few additional functionalities that were added to make the simulation more realistic

Results

This was the final course that I used. The purpose for this course was for it to look realistic and have an slightly uneven surface. All of the previously mentioned functionalities were combined and implemented into this course.

In this case: