A ramp that deflects the balls

This week, I wanted to use the knowledge of forces to construct and simulate a realistic ramp. I wanted the ramp to deflect the ball in a realistic way based on the ball's angle of incidence. I decided to do the ramp because I realized after watching the videos that the friction that was talked about in the book was actually more of wind resistance (like Shiffman mentions). So I thought of simulating an actual ramp type of friction that we have studied about in high school. When I just started building the class for the ramp, I realized that there is no simple way of evaluating if the ball has hit the ramp or not. I did some research and asked around in the Nature of Code group. I tried the slope method of calculating whether the ball has hit the ramp. This, I thought would give whether it has hit the ramp; However, I wanted the ball to bounce off based on the angle of incidence and the angle of ramp as well. Hence I learnt that I would need to calculate the angle of incidence of the ball hitting the ramp. So, I decided to do the dot product method to calculate the normal distance between the ball and the line representing the ramp. If the perpendicular distance between the ball and the ramp is equal to the radius of the ball, that means it has hit the surface. As far as deflection angle goes, I used the Angle of Incidence = angle of Reflection formula, which I found out to be true for object deflection as well. The deflection is achieved by using the rotate() function of PVector to change the angle of the velocity at the moment of impact.

I have made a ramp class that draws out a ramp and calculates the above mentioned values. One end of the ramp is fixed and the other is free to move about based on the mouse location. Going forward, I want to make a slightly larger environment where there is wind, gravity friction in the ramp, and multiple ramps as well to calculate realistic physics.