Plot of a butterfly using mathematical equations
18 views (last 30 days)
Show older comments
Ahmed Mohamed Mansoor
on 2 Oct 2022
Edited: Ahmed Mohamed Mansoor
on 3 Oct 2022
Hello, I saw these set of equations that plot a butterfly using circles (See Image Below). I was able to code it down and the plot seems to be okay. However, there are a few issues with my code and it would be great if anybody could help.
My questions are:
1) Is the code correct?
2) Is there a faster method of plotting these circles. The current code takes quite a while for it to plot.
3) How can i get a color scheme based on the picture above?
The code that I attempted was as follows:
clear; close all; clc;
sin1 =@(k) sin((pi*k)./40000);
cos1 =@(k) cos((pi*k)./40000);
sin141=@(k) sin((141*pi*k)./40000);
cos141=@(k) cos((141*pi*k)./40000);
sin2 =@(k) sin((2*pi*k)./40000);
cos2 =@(k) cos((2*pi*k)./40000);
cos32 =@(k) cos((32*pi*k)./40000);
sin6 =@(k) sin((6*pi*k)./40000);
sin18 =@(k) sin((18*pi*k)./40000);
cos3 =@(k) cos((3*pi*k)./40000);
cos21 =@(k) cos((21*pi*k)./40000);
cos12 =@(k) cos((12*pi*k)./40000);
x = 1:40000;
Xk = (3/2)*cos141(x).^9 .* (1-0.5*sin1(x)) .* (1 - 0.25*cos2(x).^30 .* ...
(1+cos32(x).^20)) .* (1 - 0.5*sin2(x).^30 .* sin6(x).^10 .* ...
(0.5 + 0.5*sin18(x).^20));
Yk = cos2(x) .* cos141(x).^2 .* (1+0.25*(cos1(x).*cos3(x).*cos21(x)).^24);
Rk = 0.025 .* (cos141(x).^14 + sin141(x).^6) .* (1- (cos1(x).*cos3(x).*...
cos12(x)).^16) + 0.01;
axis([-1.5 1.5 -1 1.5])
for i = 1:length(x)
viscircles([Xk(i), Yk(i)], Rk(i),'Color',[0.7 0.7 0.7]);
drawnow
pause(10^-10000)
end
Your help would be appreciated.
Thank you
0 Comments
Accepted Answer
KSSV
on 2 Oct 2022
Edited: KSSV
on 2 Oct 2022
clc; clear all ;
clear; close all; clc;
sin1 =@(k) sin((pi*k)./40000);
cos1 =@(k) cos((pi*k)./40000);
sin141=@(k) sin((141*pi*k)./40000);
cos141=@(k) cos((141*pi*k)./40000);
sin2 =@(k) sin((2*pi*k)./40000);
cos2 =@(k) cos((2*pi*k)./40000);
cos32 =@(k) cos((32*pi*k)./40000);
sin6 =@(k) sin((6*pi*k)./40000);
sin18 =@(k) sin((18*pi*k)./40000);
cos3 =@(k) cos((3*pi*k)./40000);
cos21 =@(k) cos((21*pi*k)./40000);
cos12 =@(k) cos((12*pi*k)./40000);
x = 1:40000;
Xk = (3/2)*cos141(x).^9 .* (1-0.5*sin1(x)) .* (1 - 0.25*cos2(x).^30 .* ...
(1+cos32(x).^20)) .* (1 - 0.5*sin2(x).^30 .* sin6(x).^10 .* ...
(0.5 + 0.5*sin18(x).^20));
Yk = cos2(x) .* cos141(x).^2 .* (1+0.25*(cos1(x).*cos3(x).*cos21(x)).^24);
Rk = 0.025 .* (cos141(x).^14 + sin141(x).^6) .* (1- (cos1(x).*cos3(x).*...
cos12(x)).^16) + 0.01;
scatter(Xk,Yk,[],Rk)
colormap(jet)
axis([-1.5 1.5 -1 1.5])
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots 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!