Help in Matlab Assigment (Plot Circles)

First Plot Circles
a-) Write MATLAB function called [x,y]=createCircle(center,r). The circle should be centered at center (1x2 row vector). Return x and y coordinates of the circle and then plot the circle. Remember that for a circle at origin (0,0) following equation is true
x(t) = cos(t)
y(t) = sin(t) for t = [0,2π].
Now, you need to find out how to scale and translate the circle.
Second

5 件のコメント

Adam Danz
Adam Danz 2019 年 12 月 23 日
We don't do other people's homework. After you get this started on your own, if you get stuck, show us your code and explain what's wrong and we can give you hints.
Enes Balci
Enes Balci 2019 年 12 月 23 日
Oh ok then, is it ok for this question?
function h = circle(x,y,r)
hold on
t = 0:2*pi;
xunit =r*cos(t);
yunit =r*sin(t);
h = plot(xunit, yunit);
hold off
Adam Danz
Adam Danz 2019 年 12 月 23 日
That function should plot a circle centered at (x,y) with radius r.
Image Analyst
Image Analyst 2019 年 12 月 23 日
It should (is supposed to), but it doesn't. And it should also take and return vectors, which it doesn't yet.
Close, but see my corrections in my answer below.
Adam Danz
Adam Danz 2019 年 12 月 23 日
編集済み: Adam Danz 2019 年 12 月 23 日
ah, well, t needs to be incremented and axis equal will help, too.
t = 0:.01:2*pi; % or linspace()

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

 採用された回答

Image Analyst
Image Analyst 2019 年 12 月 23 日

1 投票

This is a frequently asked question, so see the FAQ
For your code, you need to modify it to take more points because going from 0 to 2*pi in steps of 1 makes for a pretty chunky circle. Make it like 1000 steps with linspace(). You also need to add x center to xunit and the y center to yunit to get the center in the right place, and pass in a 1x2 vector and pass out the coordinates of the circle's perimeter.
function [xunit, yunit] = circle(xy,r)
hold on
t = linspace(0, 2*pi, 1000); % 1000 points between 0 and 2*pi
xunit = r * cos(t) + xy(1);
yunit = r * sin(t) + xy(2);
plot(xunit, yunit);
grid on;
hold off
Then you call call it like
[x, y] = circle([10, 20], 5)

1 件のコメント

Adam Danz
Adam Danz 2019 年 12 月 23 日
axis equal
so it looks like a circle

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2019 年 12 月 23 日

コメント済み:

2019 年 12 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by