File Exchange

## Draw randomly centered circles of various sizes

version 2.2.0 (6.71 KB) by Adam Danz

### Adam Danz (view profile)

Set the range of radii, density, and other parameters to create a plot that draws randomly centered polygons with or without overlap.

8 Downloads

Updated 07 Apr 2020

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function plots circles or other polygons at random positions with varying radii. All input parameters are optional including the axes size, the range of radii, number of vertices per bubble (eg, polygon shape), density, the amount of space between bubbles or how much they can overlap, how they should fit within the figure, and other parameters. A figure is produced and there are four outputs that allow the user to make further changes to the plotted objects or to recreate the exact same plot.

More detail is included at the top of the function and I've provided examples of how to use the outputs to add color, calculate the area of each circle, count the number of circles for each circle size, etc.

Follow this page for updates.

### Cite As

Adam Danz (2020). Bubblebath.m (https://www.mathworks.com/matlabcentral/fileexchange/70348), MATLAB Central File Exchange. Retrieved April 7, 2020.

ibrahim simsek

### ibrahim simsek (view profile)

Mr. Danz

First of all, the code was perfect. Thank you for your effort. But I have a question on my mind. In a random system, will the ratio of the [(total area-area of ​​the all circles which are inside the rectangle)/(total area)] (porosity) be entered as input? Is it possible to create such a system in Matlab?

Have a nice day

Antoine Deblais

Adam Danz

### Adam Danz (view profile)

@Guang Lu, the error you experienced was due to using an older version of Matlab prior to r2016b when explicit expansion was not allowed. Nevertheless, I updated the file so that it avoids explicit expansion errors in earlier versions of matlab.

Guang Lu

### Guang Lu (view profile)

There is an error in line 131

### Updates

 7 Apr 2020 2.2.0 S.circPoints added to control shape of polygon. Unrecognized input fields will throw warning instead of error. EdgeType=1 now fits more bubbles. Removed backtrace from max iteration warning. maxCircsPerRadius replaced with maxCircsPerRad. 3 Feb 2020 2.1.0 S.nSizes was misrepresented in the outputs when its input value was NaN. Updated waitbar message to include number of circles being processed. 2 Feb 2020 2.0.0 Converted to proper function with optional inputs; added several new options to supress internal warnings, control overlap, avoid memory problems, and more. Updated documentation and input validation. 2 Sep 2019 1.2.0 Updated to work with matlab releases prior to r2016b in response to Guang Lu's comment. Also added a waitbar to show progress.
##### MATLAB Release Compatibility
Created with R2018a
Compatible with R2016a to any release
##### Platform Compatibility
Windows macOS Linux