There is an algorithm for polygon formation and i want to make a star, how can i ?

2 visualizaciones (últimos 30 días)
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 comentario
Jonas
Jonas el 6 de Jul. de 2021
Editada: Jonas el 6 de Jul. de 2021
you can plot a start (pentagram) using the plot command, e.g. plot(3,'p','MarkerSize',20), or you use insertMarker()
or are you searching for a more general solution?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by