# how to avoid overlapping when drawing dots using screen function?

7 views (last 30 days)
Jinyi Tao on 9 Feb 2016
Answered: sam0037 on 15 Feb 2016
I am a beginner in Matlab and Psychtoolbox. I want to plot random number of dots between 1 to 10, but I don't know how to avoid the overlapping. These are my codes:
n = randi([1 8]); n(n==5) = 9;
DataBase=[];
DataBase = [DataBase, n];
dots.nDots = Shuffle(DataBase);
dots.col = black;
dots.size = 30;
dots.center = [960, 540];
dots.apertureSize = [900, 900];
dots.x = (rand(1,dots.nDots)-.5)*dots.apertureSize(1) + dots.center(1);
dots.y = (rand(1,dots.nDots)-.5)*dots.apertureSize(2) + dots.center(2);
Screen('DrawDots', mainwin, [dots.x;dots.y], dots.size, dots.col, [0, 0], 2);
Thank you for helping!!

#### 1 Comment

Jan on 9 Feb 2016
The start of teh code ist strange. dots.nDots is a scalar from the set [1:4, 6:9]. Neither the concatenation nor the shuffeling is meaningful. Shorter:
dots.nDots = randi([1, 8]);
if dots.nDots == 5
dots.nDots = 9;
end
But then I do not see the connection to the description: "random number of dots between 1 to 10".

sam0037 on 15 Feb 2016
Hi Jinyi,
I do not have a Psychtoolbox installed currently and hence cannot reproduce this issue. But from the above code, I understand that when you plot a set of dots of certain size(size of all dots are fixed in this case), some of them overlap which you would like to avoid. Two dots say D1 and D2 will overlap only when radius(D1)+radius(D2)<=distance between centers of D1 and D2. I hope this helps in redesigning the algorithm to suit your use case. If this is not what you were looking for, please elaborate on the use-case.
Thanks, Shamim
{"ft_lang_label":"__label__en","ft_lang_prob":0.5376634,"math_prob":0.9054332,"size":769,"snap":"2020-34-2020-40","text_gpt3_token_len":246,"char_repetition_ratio":0.13071896,"word_repetition_ratio":0.06557377,"special_character_ratio":0.3407022,"punctuation_ratio":0.2947977,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9549447,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-22T11:03:24Z\",\"WARC-Record-ID\":\"<urn:uuid:acb8f3d3-e4f4-4a71-8a02-dfa85c6cfadd>\",\"Content-Length\":\"107514\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0068bb52-d33d-4b4c-88cf-47c00d17104f>\",\"WARC-Concurrent-To\":\"<urn:uuid:a80de5a9-f1ef-41f8-a617-cbc06987eec4>\",\"WARC-IP-Address\":\"23.212.144.59\",\"WARC-Target-URI\":\"https://se.mathworks.com/matlabcentral/answers/267364-how-to-avoid-overlapping-when-drawing-dots-using-screen-function\",\"WARC-Payload-Digest\":\"sha1:MXBFKUW73HVEGWGCQCDP4X424IN3ILUM\",\"WARC-Block-Digest\":\"sha1:JEHMPDVCZODZ4XOEMRJW6XRPN34O4IAB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600400205950.35_warc_CC-MAIN-20200922094539-20200922124539-00110.warc.gz\"}"}