fill the area between multiple curves

4 次查看(过去 30 天)
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 );

采纳的回答

Cameron
Cameron 2023-1-3
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 个评论
Cameron
Cameron 2023-1-3
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 2023-1-4
Yes! It worked!
Thanks I really appriciated it!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by