Physically-Based Modeling

Homework 1

Code
Home

Basic Application

A screenshot of the ballistic application. The trajectory calculated via the selected method is shown in red, while the trajectory calculated by te closed form solution is showng in blue

A screenshot of the mass spring application. The mass is in red is calculated via the selected method and the mass in green is calculated via a closed form solution.

A screenshot of the ballistic and spring mass controller windows, left and right respectively. These windows were created with the GLUI toolkit and gives the user the option of specifying the method along with some of the parameters of the simulation.

Method efficiency

Below is a table of the most common run times in nanoseconds for each method in the ballistic and spring mass simulation. The time for each calculation is as expected. Euler takes the least time, Midpoint takes longer, since 2 derivatives are needed and RK4 takes the longest as 4 deviates are needed.

MethodBalisticsMass Spring
Euler1418
Midpoint2025
RK43745

Error analysis

Next we will compare the three methods with respect to there error for our three methods for each method, all the graphs were created from t = 0 to 5 with a time step of .1 and no air drag. To get an idea about how quickly error is introduced by the different methods. For the ballistic motion the parameters were set at mass=110, powder amount=11.768, azimuth=12, elevation=37.6769. For the mass spring, parameters were set at mass=5, and k=15. The plots below show the L2 error of the method compared to the result from the closed from solution. From the plots it is clear that Euler produces the most error, Midpoint has a substantially smaller error, and RK4 is even smaller yet. It is also important to note that while all the methods introduce error, the Euler method quickly becomes wildly unstable in the mass spring simulation, this even occurs when the time step is very small (.001). One final note is that with respect to numerical stability, RK4 would be the least stable problems because it contains the most computation coupled with the fact that the constant scaling of (1/6) must be approximated (1/6 cannot be represented exactly in floating point hardware). From testing I was not able to find any example were this caused RK4 to accumulate more error then Euler or Midpoint.

Euler Midpoint RK4
Balistics
Mass spring