There is an algorithm for polygon formation and i want to make a star, how can i ?
2 views (last 30 days)
Show older comments
clc;
clear all;
close all;
m = 20;
[a1,a2,a3] = generate_alphas(m);
% draw the polygone
n = 8;
angle = 360/n;
r = 1;
x1 = r*cosd(0*angle);
y1 = r*sind(0*angle);
figure(1)
hold on
axis equal
% draw axis
t = 1.3;
p1x = t*[-1 0];
p2x = t*[1 0];
p1y = t*[0 -1];
p2y = t*[0 1];
line([p1x(1) p2x(1)],[p1x(2) p2x(2)],'color','black','linewidth',2)
line([p1y(1) p2y(1)],[p1y(2) p2y(2)],'color','black','linewidth',2)
points = zeros(2,n);
for i=1:n
x2 = r*cosd(i*angle);
y2 = r*sind(i*angle);
points(:,i) = [x2,y2]';
line([x1,x2],[y1,y2],'color','red','linewidth',3);
pause(0.5);
% fill the triangle
px = 0*a1+a2*x1+a3*x2;
py = 0*a1+a2*y1+a3*y2;
plot(px,py,'.');
x1 = x2;
y1 = y2;
end
function [a1,a2,a3] = generate_alphas(n)
a = linspace(0,1,n);
a1 = zeros(1,1+n*(n+1)/2);
a2 = zeros(1,1+n*(n+1)/2);
q = 0;
for i=1:n
s = 0:n-i;
a1(q+s+1) = s*0+a(i);
a2(q+s+1) = a(s+1);
q = q+n+2-i;
end
a3 = 1-a1-a2;
end
1 Comment
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!