how to avoid overlapping when drawing dots using screen function?

3 ビュー (過去 30 日間)
Jinyi Tao
Jinyi Tao 2016 年 2 月 9 日
回答済み: sam0037 2016 年 2 月 15 日
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
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
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

カテゴリ

Help Center および File ExchangeImage display and manipulation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by