For more on the grid based collision system approach with code examples, see:
…and previously https://forum.processing.org/two/discussion/17830/how-do-i-iterate-through-individual-buckets-in-hashmaps
…and also, see this chapter with code examples:
Ch.6 from Nature of Code – in particular section 6.14 “Algorithmic Efficiency (or: Why does my $@(*%! run so slowly?)” The Nature of Code
… noc-examples-processing/chp06_agents/binlatticespatialsubdivision at master · nature-of-code/noc-examples-processing · GitHub
However note that these approaches do not satisfy “A ball is said to be in a cell if more than 50% of the area of the ball is within the cell.”