{"id":11319,"date":"2020-02-24T15:00:06","date_gmt":"2020-02-24T20:00:06","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=11319"},"modified":"2020-02-24T20:53:17","modified_gmt":"2020-02-25T01:53:17","slug":"draw-a-bubble-bath","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2020\/02\/24\/draw-a-bubble-bath\/","title":{"rendered":"Draw a bubble bath"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871\">Jiro<\/a>&#8216;s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/70348\"><tt>bubblebath<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3753776\">Adam Danz<\/a>.<\/p><p>Adam is no stranger to File Exchange and File Exchange Pick of the Week. He is even more active on <a href=\"https:\/\/jp.mathworks.com\/matlabcentral\/profile\/authors\/3753776-adam-danz?utf8=%E2%9C%93&amp;detail2=&amp;detail=answers\">MATLAB Answers<\/a>. In fact, this entry by Adam stemmed from a <a href=\"https:\/\/jp.mathworks.com\/matlabcentral\/answers\/446114\">question<\/a> on MATLAB Answers. The original poster asked for ways of creating non-overlapping randomly placed circles within a region, with an ability to specify some parameters such as number of circles and min\/max radii.<\/p><p>Let&#8217;s look at an example. Here, we will create circles with 10 linearly spaced different radii ranging from 1 to 10.<\/p><pre class=\"codeinput\">S.circSize = [1 10];\r\nS.nSizes = 10;\r\nS.supressWarning = true;\r\nbubblebath(S);\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bubblebath_01.png\" alt=\"\"> <p>Next, we specify the exact set of radii for the circles.<\/p><pre class=\"codeinput\">S.circSize = [0.5 1 1.5 3 5 20];\r\nS.nSizes = NaN;\r\nbubblebath(S);\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bubblebath_02.png\" alt=\"\"> <p>I appreciate the effort he took to create this entry after some discussions on MATLAB Answers. He has also updated his entry based on the comments.<\/p><p>The other thing I really like is the detailed documentation (help) he includes with the function and the thorough error-checking for the input arguments. Those of you who have read some of my recent posts (<a href=\"https:\/\/blogs.mathworks.com\/pick\/2019\/09\/27\/new-with-r2019b-function-argument-validation\/\">this<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/pick\/2019\/10\/18\/spider-plots-and-more-argument-validation\/\">this<\/a>) know that I am a big fan of the new <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/function-argument-validation-1.html\">Function Argument Validation<\/a> that was introduced in R2019b. I understand that Adam wrote his function in an older release, but once he upgrades to the newest release, I encourage him to give it a try!<\/p><p>Lastly, I&#8217;d like to give a shout-out to a few other entries that were mentioned in the MATLAB Answers post.<\/p><div><ul><li><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/71088-random-circle-packing-in-a-rectangle-with-dxf-output\">Random Circle Packing in a Rectangle With DXF Output<\/a><\/li><li><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/56601-random-close-packing-rcp-on-arbitrary-distribution-of-circle-sizes\">Random close packing (RCP) on arbitrary distribution of circle sizes<\/a><\/li><li><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/33213-growbubbles-maximum-radius-packing\">Growbubbles &#8211; maximum radius packing<\/a><\/li><\/ul><\/div><p><b>Comments<\/b><\/p><p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=11319#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/70348#comment\">comment<\/a> for Adam.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_225c32f4e0334bcbaa2ce0747ec1a291() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='225c32f4e0334bcbaa2ce0747ec1a291 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 225c32f4e0334bcbaa2ce0747ec1a291';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2020 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_225c32f4e0334bcbaa2ce0747ec1a291()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2019b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2019b<br><\/p><\/div><!--\r\n225c32f4e0334bcbaa2ce0747ec1a291 ##### SOURCE BEGIN #####\r\n%%\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871 Jiro>'s\r\n% Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/70348 |bubblebath|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3753776 Adam\r\n% Danz>.\r\n%\r\n% Adam is no stranger to File Exchange and File Exchange Pick of the Week.\r\n% He is even more active on\r\n% <https:\/\/jp.mathworks.com\/matlabcentral\/profile\/authors\/3753776-adam-danz?utf8=%E2%9C%93&detail2=&detail=answers\r\n% MATLAB Answers>. In fact, this entry by Adam stemmed from a\r\n% <https:\/\/jp.mathworks.com\/matlabcentral\/answers\/446114 question> on\r\n% MATLAB Answers. The original poster asked for ways of creating\r\n% non-overlapping randomly placed circles within a region, with an ability\r\n% to specify some parameters such as number of circles and min\/max radii.\r\n%\r\n% Let's look at an example. Here, we will create circles with 10\r\n% linearly spaced different radii ranging from 1 to 10.\r\n\r\nS.circSize = [1 10];\r\nS.nSizes = 10;\r\nS.supressWarning = true;\r\nbubblebath(S);\r\n\r\n%%\r\n% Next, we specify the exact set of radii for the circles.\r\n\r\nS.circSize = [0.5 1 1.5 3 5 20];\r\nS.nSizes = NaN;\r\nbubblebath(S);\r\n\r\n%%\r\n% I appreciate the effort he took to create this entry after some\r\n% discussions on MATLAB Answers. He has also updated his entry based on the\r\n% comments.\r\n%\r\n% The other thing I really like is the detailed documentation (help) he\r\n% includes with the function and the thorough error-checking for the input\r\n% arguments. Those of you who have read some of my recent posts\r\n% (<https:\/\/blogs.mathworks.com\/pick\/2019\/09\/27\/new-with-r2019b-function-argument-validation\/\r\n% this> and\r\n% <https:\/\/blogs.mathworks.com\/pick\/2019\/10\/18\/spider-plots-and-more-argument-validation\/\r\n% this>) know that I am a big fan of the new\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/function-argument-validation-1.html\r\n% Function Argument Validation> that was introduced in R2019b. I understand\r\n% that Adam wrote his function in an older release, but once he upgrades to\r\n% the newest release, I encourage him to give it a try!\r\n%\r\n% Lastly, I'd like to give a shout-out to a few other entries that were\r\n% mentioned in the MATLAB Answers post.\r\n%\r\n% * <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/71088-random-circle-packing-in-a-rectangle-with-dxf-output Random Circle Packing in a Rectangle With DXF Output>\r\n% * <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/56601-random-close-packing-rcp-on-arbitrary-distribution-of-circle-sizes Random close packing (RCP) on arbitrary distribution of circle sizes>\r\n% * <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/33213-growbubbles-maximum-radius-packing Growbubbles - maximum radius packing>\r\n%\r\n% *Comments*\r\n%\r\n% Give it a try and let us know what you think\r\n% <http:\/\/blogs.mathworks.com\/pick\/?p=11319#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/70348#comment comment> for Adam.\r\n\r\n##### SOURCE END ##### 225c32f4e0334bcbaa2ce0747ec1a291\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_bubblebath_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nJiro&#8216;s Pick this week is bubblebath by Adam Danz.Adam is no stranger to File Exchange and File Exchange Pick of the Week. He is even more active on MATLAB Answers. In fact, this entry by&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2020\/02\/24\/draw-a-bubble-bath\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11319"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=11319"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11319\/revisions"}],"predecessor-version":[{"id":11335,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11319\/revisions\/11335"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=11319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=11319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=11319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}