How can i make a n-pointed star?

2 ビュー (過去 30 日間)
Joungyoung
Joungyoung 2014 年 12 月 8 日
編集済み: Giorgos Papakonstantinou 2014 年 12 月 9 日
--------------------------------------------------------------------------------------------
clear all; close all; clc;
N = input('natural number 1~100 : ');
m = ceil(sqrt(length(N)));
n = ceil(sqrt(length(N)));
figure('number','off'); hold on
for c = 1 : length(N) ;
if rem(N(1,c),2)==1 %odd number
t = 0:N:N(1,c)*N(1,c);
x = cos((N(1,c)-1)/N(1,c)*pi*t);
y = sin((N(1,c)-1)/N(1,c)*pi*t);
else %even number(Now, even number code = odd number code)
t = 0:N.*N:N(1,c)*N(1,c);
x = cos((N(1,c)-1)/N(1,c)*pi*t);
y = sin((N(1,c)-1)/N(1,c)*pi*t);
end
subplot(m,n,c); hold on
plot(x,y)
hold off
end
hold off
---------------------------------------------------------------------------------------------
I'm student of korea ,which learning MATLAB
I input vector 1:9, this figure out.
if I input odd number, maked n-pointed star. but I input even number, maked 2n-pointed star.
How can I n-pointed star???? please

回答 (1 件)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014 年 12 月 9 日
編集済み: Giorgos Papakonstantinou 2014 年 12 月 9 日
Hello student from Korea!
Why don't you try this?
q = 4; % connect every qth point out of p points
mingon = 2*q + 1;
maxgon = mingon + 11;
jj = 0;
for ngon = mingon:maxgon;
theta = linspace(0, 2*pi, ngon+1);
[xx, yy] = pol2cart(theta, 1);
K = diag(ones(q,1), ngon-q)+diag(ones(ngon-q,1), q)+diag(ones(q,1), -ngon+q)+diag(ones(ngon-q,1), -q); % adjacency matrix
jj = jj + 1;
subplot(3, 4, jj)
gplot(K, [xx' yy'])
hold all
plot(xx, yy)
axis equal
title(['\{' num2str(ngon, '%d') '/' num2str(q, '%d') '\}'])
end
  1 件のコメント
Image Analyst
Image Analyst 2014 年 12 月 9 日
Wow. Pretty cool.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by