How to "color" the closed area bounded by three curves

13 ビュー (過去 30 日間)
mukesh bisht
mukesh bisht 2021 年 11 月 12 日
編集済み: Simran 2025 年 4 月 29 日
Hi, I want to color the area between the intersection of three curves. Please suggest a way.
Code Updated by @Sam Chak: (based on info in Comment)
T1 = 180:0.1:270;
x1 = 3*cosd(T1);
y1 = 3*sind(T1); % circle
T2 = 3.3620:0.001:3.9045;
c1 = 4.3123; c2 = -50.2708; c3 = 193.7277; c4 = -243.8411;
r_6 = c1*T2.^3 + c2*T2.^2 + c3*T2 + c4;
x2 = 1.1998 + r_6.*cos(T2);
y2 = -0.8840 + r_6.*sin(T2); % region 4
x0 = 1.8977;
y0 = 2.3235;
vr = 4.0678;
beta = atan(y0/x0);
x3 = -2.0591:0.001:-1.8541;
y3 = y0 + (x0-x3)*cot(beta) - (9.81*(x0-x3).^2)./(2*(vr*sin(beta))^2); % parabola
pgon1 = polyshape(x1,y1); % circle
pgon2 = polyshape(x2,y2); % region 4
pgon3 = polyshape(x3,y3); % parabola
pgon4 = intersect(pgon1,pgon2);
figure(4)
plot(x1, y1, x2, y2, x3, y3, 'linewidth', 2)
hold on
plot(intersect(pgon3, pgon4), 'EdgeColor', 'none')
grid on
axis equal
  6 件のコメント
Star Strider
Star Strider 2021 年 11 月 12 日
... still more problems ...
T2 = 3.3620:0.001:3.9045;
T1 = 180:0.1:270;
x1 = 3*cosd(T1); y1 = 3*sind(T1);
T2 = 3.3620:0.001:3.9045;
c1 = 4.3123; c2 = -50.2708; c3 = 193.7277; c4 = -243.8411;
r_6 = c1*T2.^3 + c2*T2.^2 + c3*T2 + c4;
x2 = 1.998 + r_6.*cos(T2); y2 = -0.8840 + r_6.*sin(T2);
x0 = 1.8977; y0 = 2.3235; vr = 4.0678;
beta = atan(y0/x0);
x3 = s2(1,1):0.001:x_t; y3 = y0 + (x0-x3)*cot(beta) - (9.81*(x0-x3).^2)./(2*(vr*sin(beta))^2);
Unrecognized function or variable 's2'.
pgon1 = polyshape(x1,y1);
pgon2 = polyshape(x2,y2);
pgon3 = polyshape(x3,y3);
figure (1)
plot(x1,y1,x2,y2,x3,y3)
hold on
plot (intersect(intersect(pgon3,pgon4)), pgon3,'EdgeColor','none')
I would really like to be able to run this in order to see what the problems are.
.
mukesh bisht
mukesh bisht 2021 年 11 月 13 日
sorry for my incorrect code. Here, is the final corrected version
T1 = 180:0.1:270;
x1 = 3*cosd(T1); y1 = 3*sind(T1); % circle
T2 = 3.3620:0.001:3.9045;
c1 = 4.3123; c2 = -50.2708; c3 = 193.7277; c4 = -243.8411;
r_6 = c1*T2.^3 + c2*T2.^2 + c3*T2 + c4;
x2 = 1.1998 + r_6.*cos(T2); y2 = -0.8840 + r_6.*sin(T2); % region 4
x0 = 1.8977; y0 = 2.3235; vr = 4.0678;
beta = atan(y0/x0);
x3 = -2.0591:0.001:-1.8541; y3 = y0 + (x0-x3)*cot(beta) - (9.81*(x0-x3).^2)./(2*(vr*sin(beta))^2); % parabola
pgon1 = polyshape(x1,y1); % circle
pgon2 = polyshape(x2,y2); % region 4
pgon3 = polyshape(x3,y3); % parabola
pgon4 = intersect(pgon1,pgon2);
figure (4)
plot(x1,y1,x2,y2,x3,y3)
hold on
plot (intersect(pgon3,pgon4),'EdgeColor','none')
I want to color the area of intersection of these threee curves

サインインしてコメントする。

回答 (1 件)

Simran
Simran 2025 年 4 月 28 日
編集済み: Simran 2025 年 4 月 29 日
The common area between the polygons 'pgon3' and pgon4' isn't being plotted because the 'intersect' function doesn't find any common points between the 2 regions and thus returns an object having an empty matrix for 'Vertices' field, when you run
>> intersect(pgon3,pgon4)
To visualise your plots better, you can try plotting the polygon regions ('pgon1', 'pgon2' etc one after the other) and then decide which polygons to send to the 'intersect' function to compute the common points. You can refer the following code snippet:
>> figure
>> hold on
>> plot(pgon3)
>> plot(pgon1)
>> plot(pgon2)
You can refer to the below documentation links:

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by