필터 지우기
필터 지우기

generate coordinates circle,square,rectangle

조회 수: 29 (최근 30일)
Tomas
Tomas 2014년 2월 28일
편집: Will Reeves 2018년 4월 6일
Hello,
I have to generate points(matrix),so that i have view the points as a circle(square,rectagle), when i display points(matrix) through plot.
Could someone help me?
Thanks.

채택된 답변

Image Analyst
Image Analyst 2014년 3월 2일
For circle and ellipse, see the FAQ for code examples: http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=7341#How_do_I_create_a_circle.3F
For a square or rectangle, if you have x1, x2, y1, and y2, you can make it with plot by making coordinates of the box and calling plot
xBox = [x1 x2 x2 x1 x1];
yBox = [y1 y1 y2 y2 y1];
plot(xBox, yBox, 'r-', 'LineWidth', 2);
Of course that can ge generalized to any polygon, just list all the vertices.

추가 답변 (1개)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014년 3월 2일
% circle
r=1; % radius
C=[1 1];
theta=0:2*pi/360:2*pi; % the angle
m=r*[cos(theta')+C(1) sin(theta')+C(2)]; % the points you asked
plot(m(:,1), m(:,2))
axis equal
hold all
% Rectangle
a=1; % side a
b=.5; % side b
s=[0.5 0.75]; % bottom left start point
A=[s(1) s(1)+a s(1)+a s(1) s(1);s(2) s(2) s(2)+b s(2)+b s(2)];
plot(A(1,:), A(2,:))
axis equal
  댓글 수: 1
Will Reeves
Will Reeves 2018년 4월 6일
편집: Will Reeves 2018년 4월 6일
nice... although the "r*" shouldn't apply to the centre coordinate offset:
m=r*[cos(theta') sin(theta')] + C; % the points you asked
instead of this:
m=r*[cos(theta')+C(1) sin(theta')+C(2)]; % the points you asked
Or am I being silly?!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by