How to set a specific distance between new point and previous calculated points?

Hello, I try to generate a set of points using the fermat spiral equations teta(i)=2*pi*(phi^-2)*i; r(i)=a*i^b These points represent heliostats and I would like to avoid overlapping or collision so my question is i would like to ensure a certain euclidien distance between new point (xi,yi) and previous calculated points. Looking for your reply.

 Accepted Answer

The following code will generate a spiral, while ensuring that distance between consecutive point is greater then a threshold
phi = 2;
a = 1;
b = 1;
threshold = 0.1;
totalPoints = 1000;
i = zeros(1, totalPoints);
r = zeros(1, totalPoints);
theta = zeros(1, totalPoints);
di = 0.01;
count = 1;
failCounter = 1;
while count < totalPoints
testPoint = i(count)+failCounter*di;
thetaTestPoint = 2*pi/phi^2*testPoint;
rTestPoint = a*testPoint.^b;
[xTestPoint, yTestPoint] = pol2cart(thetaTestPoint, rTestPoint);
[x, y] = pol2cart(theta(count), r(count));
distance = norm([xTestPoint, yTestPoint] - [x, y]);
if distance > threshold
count = count + 1;
i(count) = testPoint;
r(count) = rTestPoint;
theta(count) = thetaTestPoint;
failCounter = 0;
end
failCounter = failCounter + 1;
end
polarplot(theta, r)
It will generate totalPoints number of points, which are at least threshold distance apart.

1 Comment

I appreciate your immense effort, but Sir Hamza the final pattern should look like that (image attached),in fact these are the value i should work with a=2; b=0.5; phi = (sqrt(5)+1)/2; and thanks again

Sign in to comment.

More Answers (1)

r = zeros(25,1);
c= 20;
theta = zeros(25,1);
for i = 1:25
r(i) = c*sqrt(i);
theta(i) = i*137.508;
end
theta = deg2rad(theta);
[M,N]= size(f);
x = r.*cos(theta);
y = r.*sin(theta);
b = zeros(M,N);
for i = 1:25
b(round(M/2+x(i)) , round(N/2+y(i))) = 1;
end
figure();imagesc(abs(b));colormap('gray')

Products

Community Treasure Hunt

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

Start Hunting!