How to write a code for "N points on a Fibonacci spiral placed within the circle"?
15 views (last 30 days)
Show older comments
Hi.
First excuse me for my bad English and my knowledge for Matlab. I found a web link http://people.sc.fsu.edu/~%20jburkardt/m_src/circle_grid/circle_grid.html circle_grid* that has this kind of code under name: circle_grid_test02.m But i cant get the test program to work,always some errors.. Could somebody check that link please and copy here the code that i have to paste it to the editor to make it work? Or perhaps there is some easy way for that or some other program? I just need to specify radius of a circle and how many dots i want in that. Thanks
0 Comments
Accepted Answer
Roger Stafford
on 11 Dec 2013
I have checked out the 'circle_grid_fibonacci' function on the web site you referenced (although the link you gave had a mistake in spelling) and found that this function works very well and gives what appears to be a true Fibonacci spiral. The purpose behind the spiral is presumably to arrange the "grid" points so as to have area-wise as uniform a distribution as possible within a circle.
I don't know what kind of trouble you had with the test routine 'circle_grid_test02.m', but it is very easy to test out 'circle_grid_fibonacci' with your own code. The output of this function is an array which is of n x 2 size, so you just need to plot the first column as the x coordinates against the second column as the y coordinates.
If I were writing the code I would have used the following more compact version, where n is the desired number of points, r is the circle's radius, and c is a 2-element vector contained the x,y coordinates of the circle's center.
R = r*sqrt(linspace(1/2,n-1/2,n))/sqrt(n-1/2);
T = 4/(1+sqrt(5))*pi*(1:n);
X = c(1)+R.*cos(T);
Y = c(2)+R.*sin(T);
plot(X,Y,'yo')
axis equal
3 Comments
Roger Stafford
on 11 Dec 2013
Well, it's actually a spiral in that each successive step moves outward to a larger distance from the center, and the angle change for each step is always the same. However, at each step it sweeps a whopping 222 degrees, so it looks rather strange as spirals go. If you use a very high value of n, such as 1000, and omit the connecting lines, it makes a striking pattern.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!