2

I read the page Ball to Ball Collision - Detection and Handling and am a bit confused about the code for resolve_collision. I get everything except what is 1.0f + Constants.restitution? What is 1.0f and what is Constants.restitution?

Community
  • 1
  • 1
user700996
  • 463
  • 2
  • 10
  • 18

2 Answers2

3

The 1.0f is the literal for a floating point 1.0. In Java, 1.0 will default to type double, so the author is explicitly making it a float by adding the f flag afterwards.

Constants.restitution supposedly represents the coefficient of restitution, which is usually an e or Cr in physics. This defines how much a ball bounces once it hits the floor or another ball. Though he doesn't show it in the code he provided, it is probably declared somewhere as

public class Constants {
    public static final float restitution = 0.8f;
}
Austin Hyde
  • 26,347
  • 28
  • 96
  • 129
2

The coefficient of restitution is a number between 0 and 1 that indicates the amount of elasticity in the collision. A 0 means the contacting bodies will stick together, and a 1 means they will bounce off in a perfectly elastic fashion (recovering all their speed).

Try Googling coefficient of restitution and the rest will follow.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133