fill the area between multiple curves

2 Ansichten (letzte 30 Tage)
Claudio
Claudio am 3 Jan. 2023
Kommentiert: Claudio am 4 Jan. 2023
I created the sign of the nasa logo using eight circumference arcs. I plotted them in the same figure but i can't fill the area inside the shape. To plot the different arcs I used parametric equations so I'm not able to access the x and y coordinates all toghether.
Thanks for everyone answering!
%circle_th plots the arc using center coordinates, radius and parameter boundaries
circle_th(117.128, 218.51,131.4,293.8,329.71);
circle_th(355.217, -281.412,422.66,115.98,129.96);
circle_th(296.094, -178.16,306.27,116.91,133.9);
circle_th(-60.4339, 482.318,444.46,299.36,305.42);
circle_th(88.377, 331.462,237.7,279.27,297.24);
circle_th(222.873, -369.099,475.8, 101.67,109.43 );
circle_th(319.927, -503.795,636.82, 104.82, 113.64 );
circle_th(110.346, 282.953, 177.37,285.27,312.58 );

Akzeptierte Antwort

Cameron
Cameron am 3 Jan. 2023
The easiest way I know is to use the fill function documented here. Take all the x and y data from your arcs using
%you may have to do this between each circle_th use if you don't have
%another way of getting the x and y data
ax = gca; %get the axis with all your curves
x = ax.Children.XData; %grab x data
y = ax.Children.YData; %grab y data
You may need to adjust your curves and line them up head to tail using the flip function like this.
x1 = (1:20)';
y1 = x1.^2;
plot(x1,y1)
x2 = (10:0.5:20)';
y2 = 0.5*x2.^2+200;
hold on
plot(x2,y2)
x3 = [x1(1);x2(1)];
y3 = [y1(1);y2(1)];
plot(x3,y3)
x = [x1;flip(x2);x3];
y = [y1;flip(y2);y3];
fill(x,y,'r')
hold off
  3 Kommentare
Cameron
Cameron am 3 Jan. 2023
You should be able to do this
function [X,Y]=circle_th(Xc,Yc,R,th0,th1)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
th=th0:0.01:th1;
X=Xc+R*cosd(th);
Y=Yc+R*sind(th);
plot(X,Y,"Color",'r');
end
then
[X1,Y1]=circle_th(117.128, 218.51,131.4,293.8,329.71);
hold on
[X2,Y2]=circle_th(355.217, -281.412,422.66,115.98,129.96);
[X3,Y3]=circle_th(296.094, -178.16,306.27,116.91,133.9);
[X4,Y4]=circle_th(-60.4339, 482.318,444.46,299.36,305.42);
[X5,Y5]=circle_th(88.377, 331.462,237.7,279.27,297.24);
[X6,Y6]=circle_th(222.873, -369.099,475.8, 101.67,109.43);
[X7,Y7]=circle_th(319.927, -503.795,636.82, 104.82, 113.64);
[X8,Y8]=circle_th(110.346, 282.953, 177.37,285.27,312.58);
hold off
fig = figure;
ax1 = axes(fig);
x = [flip(X1),X2,flip(X3),X4,flip(X5),X6,flip(X7),X8];
y = [flip(Y1),Y2,flip(Y3),Y4,flip(Y5),Y6,flip(Y7),Y8];
fill(x,y,'r','EdgeColor','none','FaceAlpha',0.3) %I added some FaceAlpha and removed the EdgeColor
Claudio
Claudio am 4 Jan. 2023
Yes! It worked!
Thanks I really appriciated it!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by