nature-of-code / noc-examples-processing

Repository for example code from The Nature of Code book
MIT License
2.55k stars 953 forks source link

Strange behaviour in Example NOC_2_5_fluidresistance.pde #98

Closed redek91 closed 4 years ago

redek91 commented 6 years ago

Hi Dan, i found a strange behaviour while making the exercises in the book. I could reproduce the problem in the example NOC_2_5_fluidresistance.pde. Try to set movers[i] = new Mover(random(0.1, 0.2), 40+i*70, 0); at line 62 instead of movers[i] = new Mover(random(0.5, 3), 40+i*70, 0); You'll see that the small objects are actually bouncing off the liquid and going up at "speed of light".

Why is this happening? Is it to the low precision of the float data type or am I missing something?

FeralFlora commented 4 years ago

Did you find an explanation for the issue?

redek91 commented 4 years ago

@MSBack I guess it was low precision with floating point numbers in java. I could not find any other explanation.

It is fixable by seting boundaries on the acceleration variable.

This method is used to avoid oscillation.