Filling a 2D area between 3 curves (Hypocycloid)
24 views (last 30 days)
Show older comments
Hello!
My task is to plot an usual hypocycloide that is given in parametric form and to fill a specific area (have a look at the pictures). The plotting of the hypocycloide (including the big fix circle and the small rolling circle) is no problem, but the filling of the area is a problem for me. I tried a lot myself using the area, fill and patch function, but I could not receive a result.
The code is the following:
syms R r phi
%radius big (fix) circle
R=4;
%radius small (rolling) circle
r=1;
%parametric form hypocyloide (point at the rolling circle)
x(phi)=(R-r)*cos(phi)+r*cos(phi*((R-r)/r))
y(phi)=(R-r)*sin(phi)-r*sin(phi*((R-r)/r))
%parametric form big (fix) circle
x1(phi)=R*cos(phi);
y1(phi)=R*sin(phi);
%these points should give the position of the rolling circle at a specfic
%phi value (here: phi = 0.25*pi)
mx=(R-r)*cos(0.25*pi);
my=(R-r)*sin(0.25*pi);
%parametric form small (rolling) circle
x2=mx+x1*r/R;
y2=my+y1*r/R;
%plotting of hypocycloide, bigger circle, smaller circle
fplot(x,y,[0 2*pi])
hold on
fplot(x1,y1,[0 2*pi])
fplot(x2,y2,[0 2*pi])
hold off
This is how the plot looks like:
And this is the area that I want to fill (in grey). How can I fill it?
I hope that someone can help me.
Looking forward to some hints,
Mick
0 Comments
Accepted Answer
Matt J
on 22 Apr 2021
Edited: Matt J
on 22 Apr 2021
%radius big (fix) circle
R=4;
%radius small (rolling) circle
r=1;
phi=linspace(0,360,1000)*pi/180; phi(end)=[];
%parametric form hypocyloide (point at the rolling circle)
x=(R-r)*cos(phi)+r*cos(phi*((R-r)/r));
y=(R-r)*sin(phi)-r*sin(phi*((R-r)/r));
%parametric form big (fix) circle
x1=R*cos(phi);
y1=R*sin(phi);
%these points should give the position of the rolling circle at a specfic
%phi value (here: phi = 0.25*pi)
mx=(R-r)*cos(0.25*pi);
my=(R-r)*sin(0.25*pi);
%parametric form small (rolling) circle
x2=mx+x1*r/R;
y2=my+y1*r/R;
%plotting of hypocycloide, bigger circle, smaller circle
plot(x,y)
hold on
plot(x1,y1)
plot(x2,y2)
hold off
hcyc=polyshape(x,y);
circ1=polyshape(x1,y1);
circ2=polyshape(x2,y2);
reg=regions( polybuffer( subtract(circ1,union(hcyc,circ2)) ,-0.001 ));
hold on
plot(reg(3),'FaceColor',[1,1,1]/2)
hold off
axis equal,axis([-4 +4 -4 +4]),
5 Comments
Matt J
on 22 Apr 2021
For a more accurate area calculation, you should probably undo the polybuffer operation,
reg3=polybuffer(reg(3),0.001);
Area=area(reg3),
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!