Filling in the area around an ellipse?

20 次查看(过去 30 天)
I currently have an ellipse inscribed inside a square. I would like to find a way to fill in the area around the ellipse inside the rectangle, a given color. Any hints would be deeply appreciated--my code is below.
clc;clear all;imtool close all;
figure
t=linspace(0,2*pi);
ellipse_y=(128)-(160/2)*cos(t);%defines the height and width of the ellipse
ellipse_x=(128)-(232/2)*sin(t);
x1=0;x2=256;y1=0;y2=256;%creates a square frame around the entire output image
x_frame=[x1,x2,x2,x1,x1];
y_frame=[y1,y1,y2,y2,y1];
hold on
frame=plot(x_frame,y_frame,'r');%plots square frame around the entire output image
ellipse=plot(ellipse_x,ellipse_y,'r');%plots the ellipse

采纳的回答

Adam Danz
Adam Danz 2020-8-12
编辑:Adam Danz 2020-8-12
x = [x_frame, ellipse_x];
y = [y_frame, ellipse_y];
patch(x,y, 'r', 'EdgeColor', 'none')
axis equal % optional

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by