Plot of a butterfly using mathematical equations
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
KSSV
2022-10-2
编辑:KSSV
2022-10-2
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])
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!