Filling in the area around an ellipse?

23 Ansichten (letzte 30 Tage)
spider_plantt
spider_plantt am 12 Aug. 2020
Bearbeitet: Adam Danz am 12 Aug. 2020
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by