How to color the region between the cyan, black and blue curves
3 views (last 30 days)
Show older comments
How to color the region between the cyan, black and blue curves
clear all
format long
set(0,'DefaultAxesFontSize',20);
figure;
load('H_H(1).mat')
plot(x(3,:),x(4,:),'c', 'LineWidth',2)
axis([0 0.7 0 2]);
hold on
load('H_H(2).mat')
plot(x(3,:),x(4,:),'c', 'LineWidth',2)
hold on
load('BT_LP(1).mat')
plot(x(3,:),x(4,:),'b', 'LineWidth',2)
hold on
load('BT_LP(2).mat')
plot(x(3,:),x(4,:),'b', 'LineWidth',2)
hold on
line([0.3414, 0.3414], [0, 5], 'Color', 'k', 'linewidth',2);
0 Comments
Accepted Answer
Karim
on 25 Dec 2022
Edited: Karim
on 25 Dec 2022
@Atom, i believe this is related to my previous answer, if the patch method was not suitable you can augment the question there or add comments. This makes it easier for other people to track changes and solutions.
Below you can find a method using the polyshape funtion. First I will try to demonstrate the principle using the regions from your previous question, since there you provided the equations. Afterwards, I will use the the same methodology on the .mat files to plot the cyan region.
Hope it helps!
To start, let's first create the regions, starting with the black one:
% evaluate the function to set up the grid points
delta = ((24544953/12500000)/14379)*2500 : 0.01 : 7;
theta_m = 2*delta - 2*sqrt(14379*delta/2500 - 24544953/12500000) + 1193/1000;
theta_p = 2*delta + 2*sqrt(14379*delta/2500 - 24544953/12500000) + 1193/1000;
% combine the data, omit 1 point to avoid the overlapping point
delta = [fliplr(delta) delta(2:end)];
theta = [fliplr(theta_p) theta_m(2:end)];
% create a poly shape of the region
black_region = polyshape(delta,theta);
Now create the blue, red rectangular regions. For this we need to provide the four corner points of the rectangular shape:
blue_region = polyshape([ 0 5; 0 0; 0.3414 0; 0.3414 5]);
red_region = polyshape([ 0 1.8758; 0 0; 7 0; 7 1.8758]);
Finaly set up the green triangular region. For a triangle we need 3 points, but the principle is the same:
% eqn of the line --> theta = -2*delta + 2.5586
delta = [0 0 2.5586/2];
theta = [2.5586 0 0];
green_region = polyshape(delta,theta);
Now that we have the four regions, we can plot them. This is not really needed, we only do it to see is the shapes are correct, and it provides as visual aid to see the intersections we are looking for:
% plot the regions
figure
hold on
plot(black_region ,'FaceColor','black' ,'FaceAlpha',0.5)
plot(blue_region ,'FaceColor','blue' ,'FaceAlpha',0.5)
plot(red_region ,'FaceColor','red' ,'FaceAlpha',0.5)
plot(green_region ,'FaceColor','green' ,'FaceAlpha',0.5)
ylim([0 5])
xlim([0 7])
title('Regions using polyshape')
grid on
xlabel('$\delta\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$\theta\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
Now that we have the regions as polyshapes, we can use these to find the intersection regions.
For instances, lets find the intersection between the red/green and black regions:
RG_region = intersect(red_region,green_region);
RGB_region = intersect(RG_region,black_region);
% lets plot the resulting region
figure
hold on
plot(RGB_region)
ylim([0 5])
xlim([0 7])
title('Intersection region using polyshape')
grid on
xlabel('$\delta\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$\theta\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
So now, you've seen how to find inerestions of regions using the polyshape functionality. Now let's load the .mat files and try to construct those regions.
% load the data
H_H1 = load('H_H(1).mat','x'); H_H1 = H_H1.x;
H_H2 = load('H_H(2).mat','x'); H_H2 = H_H2.x;
BT_LP1 = load('BT_LP(1).mat','x'); BT_LP1 = BT_LP1.x;
BT_LP2 = load('BT_LP(2).mat','x'); BT_LP2 = BT_LP2.x;
% plot the data to see how we can reverse engineer the regions
figure
subplot(2,2,1); plot(H_H1(3,:), H_H1(4,:), 'k'); axis([0 0.7 0 2]); grid on
subplot(2,2,2); plot(H_H2(3,:), H_H2(4,:), 'c'); axis([0 0.7 0 2]); grid on
subplot(2,2,3); plot(BT_LP1(3,:),BT_LP1(4,:),'r'); axis([0 0.7 0 2]); grid on
subplot(2,2,4); plot(BT_LP2(3,:),BT_LP2(4,:),'g'); axis([0 0.7 0 2]); grid on
From the looks of it we need to combine H_H1 and H_H2 to form a sort of triangle. And BT_LP2 and BT_LP1 appear to be the same curve.
Lets start with the H_H region, we need to add a point to form the triangle, we want to set the triangle suchs that the regions overlaps. Thus we add a point at max x and y value:
% combine the data
H_H = [H_H1 H_H2];
% sort the data
[~,idx] = unique(H_H(3,:));
H_H = H_H(:,idx);
% find points of tirangle
H_H_x = max( H_H(3,:) );
H_H_y = max( H_H(4,:) );
% create the polyshape
delta = [H_H(3,:) H_H_x];
theta = [H_H(4,:) H_H_y];
H_H_region = polyshape(delta,theta);
To create the region with the circular edge, we need to add 2 points.
% get the circular edge, in the zone of intrest:
BT_LP_y1 = min( BT_LP1(4,:) );
BT_LP_y2 = max( BT_LP1(4,:) );
delta = [BT_LP1(3,:) 0 0];
theta = [BT_LP1(4,:) BT_LP_y1 BT_LP_y2];
BT_LP_region = polyshape(delta,theta);
Latsly we need a rectanglar region based on the black line, since we would like to use this region to do intersections, we make a temporary reion overlapping to the right of the black line:
K_region = polyshape([ 0.7 5; 0.7 0; 0.3414 0; 0.3414 5]);
% plot the regions
figure
hold on
plot(K_region ,'FaceColor','black','FaceAlpha',0.5)
plot(BT_LP_region ,'FaceColor','blue' ,'FaceAlpha',0.5)
plot(H_H_region ,'FaceColor','cyan' ,'FaceAlpha',0.5)
hold off
title('Regions using polyshape')
axis([0 0.7 0 2])
grid on
Now that we have all the regions plotted, we only need to find the intersection region. We can use the same principle as before. Start with the black and blue overlapping region. Then determine the intersection with the cyan region. The resulting region is the one you are looking for.
BB_region = intersect(K_region,BT_LP_region);
BBC_region = intersect(BB_region,H_H_region);
figure
plot(BBC_region)
axis([0 0.7 0 2])
title('Intersection region using polyshape')
grid on
3 Comments
Karim
on 25 Dec 2022
By using the same principle on the data in the .mat files.
I have augmented the answer to show the specific region you are looking for.
More Answers (0)
See Also
Categories
Find more on Elementary Polygons 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!