Scatter Points complying minimal distance

버전 1.1.0.0 (14.1 KB) 작성자: John BG
rectangle W H scatter fixed amount circles or saturating rectangle complying minimal distance
다운로드 수: 194
업데이트 날짜: 2017/2/16

라이선스 보기

earlier versions of similar effort attempting random points generation with distance constrain follow guess-and-check strategies, for instance
1. Stafford's randsphere.m sphere is about guessing points, it could be trimmed to the required rectangle but there are always a few points too close.
2. Cheng's RandPtsInLinearConstraints.m follows a similar approach.
3. guess-and-check is really fast but when adding the minimal distance constrain in some cases, for certain combination of W H Ap (Amount points) and R0 (minimal distance), like in Simon's QA
https://uk.mathworks.com/matlabcentral/answers/322431-randompoints-condition-distance
%%%% test 1 %%%% f2 is the function available in the above link
% randomly guessing points and stacking them progessively
H=100
W=200
D0=6 % this is diameter
% Nmax=618

Ap=[10;50;100;200;300;400;500;600] % As=21

dt=zeros(1,8)
for s=1:1:8
R0=6 % this is diameter
circles_on=0;
tic;[X,Y,D]=f2(Ap(s),H,W,D0);dt(s)=toc;
end

% dt = 0.22 0.06 0.06 0.06 0.07 2.90 0 0
it crashes Ap(5)=500

%%% test 2 %%%%%%%%%%%
H=200
W=300
R0=6 % this is diameter
% Nmax=1881

Ap=[100;300;500;700;100;1500;1800] % As=21

dt=zeros(1,8)
for s=1:1:8
R0=6 % this is diameter
circles_on=0;
tic;[X,Y,D]=f2(Ap(s),H,W,R0);dt(s)=toc;
end

% dt = 0.11 0.15 0.07 0.08 0.06 0 0 0

% crashed when after Ap 700 back to 100 intead of 1000

it randomly aborts sometimes, never reaching large amounts of points for wide areas.

basically such approach cannot guess all compliant points at the same time, or even guessing piling them up progressively while taking the whole area for the guessing at every guessing, and then a safety break has to be implemented when too many loops left guessing with no result.

An alternative to such approach is to progressively eliminate the area already assigned, guessing only next compliant random point from the area available, not from the complete area.

1. scatter_points7

given H and W size of 2D rectangle scatter_points7.m does the following:
1. calculate Nmax, the maximum amount of circles radius R0 that orderly fit in rectangle HxW
2. scatter Ap random points with spatial resolution dx =- 0.1 and dy=0.1
and spaced at least distance R0
if requested amount Ap>Nmax rand2Dpoints breaks because there
is no space to fit in so many random points complying with min
distance R0
3. calculate distance matrix Dmatrix among all points
4. return the coordinates of all generated points in X and Y, along with Dmatrix and Nmax
5. plot points
6. plot safety circles to visually verify

the amount of generated points is numel(X) and cannot be larger than Nmax
because of the request for the points to be randomly generated.

in this initial version, only manual input through message box.

call examples:
1.
[X,Y,Dmatrix,Nmax]=scatter_points7

2.
[X,Y,Nmax]=scatter_points7
2 examples how to verify distance values and check distances meet requirement > R0
1.
L=combinator(Ap,2,'c');
relD2=((X(L(:,2))-X(L(:,1))).^2+(Y(L(:,2))-Y(L(:,1))).^2).^.5
find(relD2<R0)

2.
L2=combinator(Ap,2);
Dmatrix=reshape(((X(L2(:,2))-X(L2(:,1))).^2+(Y(L2(:,2))-Y(L2(:,1))).^2).^.5,[Ap Ap]);
Dmatrix([1:21:end])=NaN ;
Dmatrix(Dmatrix<6)

2. scatter_points_saturate

given H and W size of 2D rectangle scatter_points7.m does the following:
1. calculate Nmax, the maximum amount of circles radius R0 that orderly fit in rectangle HxW
2. scatter as many random points as possible with spatial resolution dx =- 0.1 and dy=0.1
and spaced at least distance R0
3. calculate distance matrix Dmatrix among all points
4. return the coordinates of all generated points in X and Y, along with Dmatrix and Nmax
5. plot points
6. plot safety circles to visually verify

the amount of generated points is numel(X) and cannot be larger than Nmax

call examples:
1.
[X,Y,Dmatrix,Nmax]=scatter_points_saturate(100,100,3)

2.
[X,Y,Nmax]=scatter_points7
2 examples how to verify distance values and check distances meet requirement > R0
1.
L=combinator(Ap,2,'c');
relD2=((X(L(:,2))-X(L(:,1))).^2+(Y(L(:,2))-Y(L(:,1))).^2).^.5
find(relD2<R0)

2.
L2=combinator(Ap,2);
Dmatrix=reshape(((X(L2(:,2))-X(L2(:,1))).^2+(Y(L2(:,2))-Y(L2(:,1))).^2).^.5,[Ap Ap]);
Dmatrix([1:21:end])=NaN ;
Dmatrix(Dmatrix<6)

인용 양식

John BG (2024). Scatter Points complying minimal distance (https://www.mathworks.com/matlabcentral/fileexchange/61521-scatter-points-complying-minimal-distance), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2016a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.0

if rectangle area <900^2 then dx=0.1 dy=0.1
if rectangle area >=900^2
first rand with dx=1 dy=1 and circles R+dx
2nd rand shakes points (-0.5 +0.5) preserving min distance requirement
resolution for large rectangles improved, delay ~1sec

1.0.0.0