9.8: Random Circles with No Overlap - p5.js Tutorial
Why Stack Overflow recommends it
Stack Overflow users link it when asking or answering how to scatter circles, rectangles or other shapes randomly without overlap.
Recommended by 0 people across 0 different months, 2019 to 2021.
What it is
Daniel Shiffman of The Coding Train builds a circle packing style sketch in p5.js. Circles are placed at random positions and kept only if they do not overlap any earlier circle, using the dist() function for the overlap test.
What people said
Cites Steini · 2019-09 · Stack Overflow · on “Drawing Random non-Overlapping Rectangles on JPanel in Java”
EDIT: I know have corrected my Code. I saw this video [this video] . The guy there used p5.js and I wrote the Code in Java. This is the updated Code (I did not change the Box Class): while(var.box.length < var.inputCount) { temp = new Box(rng.nextInt(width - var.inputSize), rng.nextInt(height - var.inputSize), var.inputSize, var.inputSize, var.box.length+1); iterationCount++; for(int j = 0; j < var.box.length; j++) { next = var.box[j]; isOverLap = temp.getRect().intersects(next.getRect()); isUnderUI = temp.getRect().intersects(new Rectangle(0, height - 65, 300, 65)); if(!var.excludeUI) { isUnderUI = false; } if(isOverLap || isUnderUI) break; } if(!isOverLap && !isUnderUI) { var.box = addToArray(v
Cites Donald Zhu · 2020-10 · Stack Overflow · on “How to scatter shapes without overlapping while keeping them close together?”
here's something I have been trying to figure out but couldn't because I suck at math or statistics :S There are a lot of ways to scatter i.e. a bunch of divs or a p5 canvas element (sized slightly differently) without them overlapping - this [this video] is an example of doing it with circles. But if the total number of those elements is low, then there’s a chance that the cluster will be very far apart from each other, and the overall density can be quite inconsitent. Is there a way to scatter similarly sized rectangles without overlapping and remains a minimum distance from each other, but is never too far away? Ideally something like this: [LINK] And not this (which is the outcome if the only
Cites ACour008 · 2021-09 · Stack Overflow · on “Random points inside a circle: denser in the center, but avoiding overlap”
I have a function that generates random points in C# in a way that I generally like; the points are denser in the center and become less dense in outer regions of the 'circle': public static IPoint[] GeneratePointsAsCircle(int maxPoints, float scale, float radius = 26) { IPoint[] points = new IPoint[maxPoints]; int count = 0; while (count < maxPoints) { double r = rdm.NextDouble(); // rdm declared outside function, in class double theta = rdm.NextDouble() * 2.0 * Math.PI; double phi = rdm.NextDouble() * Math.PI; double sinTheta = Math.Sin(theta); double sinPhi = Math.Sin(phi); double cosPhi = Math.Cos(phi); double x = r * cosPhi; double y = r * sinPhi * sinTheta; IPoint point = new Point(x *