フィルターのクリア

How can i plot a hexagon, a triangle, a pentagon, an octagon and a circle.

25 ビュー (過去 30 日間)
OLAOYE abass
OLAOYE abass 2013 年 11 月 25 日
回答済み: Image Analyst 2022 年 1 月 3 日
What are the changes i need to make to this code to get a triangle, a pentagon, an octagon and a circle
% close all the open figure windows
close all
% create array containing 361 equally spaced points btw 0 and 2*pi
degrees = linspace(0, 2*pi, 361);
% store in the array 'c' cosine of all the values in the array 'degrees'
c = cos(degrees);
% store in the array 's' sine of all the values in the array 'degrees'
s = sin(degrees);
% calculate appropriate step size for plotting a hexagon
step = 360/6;
%plot the polygon
plot(c(1:step:361), s(1:step:361))
%set equal aspect ratio for all the axis
axis equal
  1 件のコメント
KRISHNA VAMSHI GANDURI
KRISHNA VAMSHI GANDURI 2022 年 1 月 3 日
how to give angles for every side(angle representation on plot)

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 25 日
sides = input('har mycket sides?');
step = 360/sides;
  4 件のコメント
John BG
John BG 2016 年 3 月 29 日
the commands sind and cosd take degrees directly:
sides=6
deg=[0:1:361]
c=cosd(deg)
s=sind(deg)
step=360/sides
plot(c(1:step:361),s(1:step:361));axis equal
Shyam Agarwal
Shyam Agarwal 2021 年 1 月 19 日
How can we change the length of polygon

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 1 月 3 日
@Shyam Agarwal, try nsidedpoly():
pgon1 = nsidedpoly(6);
pgon2 = nsidedpoly(6,'Center',[5 0],'SideLength',3);
plot([pgon1 pgon2])
axis equal

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by