how to avoid overlapping when drawing dots using screen function?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2016-2-9
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".
回答(1 个)
sam0037
2016-2-15
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image display and manipulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!