how to avoid overlapping when drawing dots using screen function?

2 views (last 30 days)
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
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".

Sign in to comment.

Answers (1)

sam0037
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

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!