Filling in the area around an ellipse?

17 views (last 30 days)
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

Accepted Answer

Adam Danz
Adam Danz on 12 Aug 2020
Edited: Adam Danz on 12 Aug 2020
x = [x_frame, ellipse_x];
y = [y_frame, ellipse_y];
patch(x,y, 'r', 'EdgeColor', 'none')
axis equal % optional

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!