Reputation: 99
i need a help. I am plotting attached shape with two plot command like
x1=-22.5;
x2=-37.5
y1=0;
y2=15;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
plot(x, y, 'r', 'LineWidth', 3);
hold on;
xC= 30;
yC = -30;
xR = 15;
yR = 30;
theta = 0 : 0.01 : 2*pi;
binax = xR * cos(theta) + xC;
binay = yR * sin(theta) + yC;
plot(binay, binax , 'r','linewidth',3);
But i need to plot it with one plot command. Can you please help me? Thank you.
Upvotes: 1
Views: 40
Reputation: 667
The following code makes the plot that you want. Some of your x and y values were swapped. To plot with one command you can combine your vectors with a NaN in between so that the end of the rectangle doesn't get connected to the start of the ellipse.
x1=-22.5;
x2=-37.5;
y1=0;
y2=15;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
xC= -30;
yC = 30;
xR = 30;
yR = 15;
theta = 0 : 0.01 : 2*pi;
binax = xR * cos(theta) + xC;
binay = yR * sin(theta) + yC;
x = [x, NaN, binax];
y = [y, NaN, binay];
plot(x, y, 'r', 'LineWidth', 3);
Upvotes: 2