Find Intersection coordinates of Contour and line plot

조회 수: 43 (최근 30일)
Jackson Foley
Jackson Foley 2020년 5월 14일
댓글: Leilane Passos 2023년 2월 27일
Hello,
I am trying to output the x-values for where the efficiency contour plot intersects the red and blue line. I have used the getContourLineCoordinates function to get the x and y values of the contour plot. I was then trying to find where the the x values of the lines matched those of the contour but ran into some issues. Any help would be much appreciated. Thanks!
clear
clc
clf()
% Motor data from specification
raw_peak=[0 462;2000 462;4000 462;6000 462;8000 462;10000 462;12000 462;14000 399;16000 315];
raw_cont=[0 440;2000 440;4000 440;6000 440;8000 440;10000 440;12000 440;14000 380;16000 300];
N=linspace(0,16000,60); % [rpm]%
Tq=linspace(0,462, 50); % [Nm]%
N_p_rpm_X=raw_peak(:,1); % [rpm]%
Tq_p_Nm_Y=raw_peak(:,2); % [Nm]%
N_c_rpm_X=raw_cont(:,1); % [rpm]%
Tq_c_Nm_Y=raw_cont(:,2); % [Nm]%
kc=0.1; % [W/Nm^2]%
ki=0.0; % [W/(rad/s)]%
kw=1.0e-5; % [W/(rad/s)^3]%
C=500; % [W]%
effMin=0.89; % [-]%
omega=N*pi/30; % [rad/s]
for i=1:length(omega)
for j=1:length(Tq)
Pout(i,j)=(omega(i)*Tq(j)); % [W]
Ploss(i,j)=kc*Tq(j)^2+ki*omega(i)+kw*omega(i)^3+C; % [W]
end
end
eff=max(effMin,Pout./(Pout+Ploss))*100; % [-]
eff_trans=eff';
V=[70,85,90,91,92,93,94,95,96,97,98,99];
hold on
[C,h]=contour(N,Tq,eff_trans,V);
plot(N_p_rpm_X,Tq_p_Nm_Y,'b','LineWidth', 2);
plot(N_c_rpm_X,Tq_c_Nm_Y,'r','LineWidth', 2);
clabel(C)
contourTable = getContourLineCoordinates(C);
x2=table2array(contourTable(1:end,3));
y2=table2array(contourTable(1:end,4));
N_p_rpm_X_new = [N_p_rpm_X, zeros(size(N_p_rpm_X, 1), size(x2, 2)-size(N_p_rpm_X, 2)); zeros(size(x2, 1)-size(N_p_rpm_X, 1), size(x2, 2))];
Tq_p_Nm_Y_new = [Tq_p_Nm_Y, zeros(size(Tq_p_Nm_Y, 1), size(y2, 2)-size(Tq_p_Nm_Y, 2)); zeros(size(y2, 1)-size(Tq_p_Nm_Y, 1), size(y2, 2))];
Tq_c_Nm_Y_new = [Tq_c_Nm_Y, zeros(size(Tq_c_Nm_Y, 1), size(y2, 2)-size(Tq_c_Nm_Y, 2)); zeros(size(y2, 1)-size(Tq_c_Nm_Y, 1), size(y2, 2))];
x_cord_c = N_p_rpm_X_new(abs(Tq_p_Nm_Y_new - y2)<0.1);
hf=gcf();
ha=gca();
xlim([0 16500]);
ylim([0 500]);
grid on;
xlabel('Motor Speed [rpm]');
ylabel('Motor Torque [Nm] & Motor efficiency [%]');
title('Motor Efficiency')

채택된 답변

Adam Danz
Adam Danz 2020년 5월 14일
편집: Adam Danz 2020년 5월 14일
Jackson Foley, I've just updated the getContourLineCoordinates function, please download the latest version (1.1.0). The (x,y) coordinates in the latest version are in order of proximity which is required to solve this problem easily. You'll also need the intersections() function from the file exchange.
Then, the intersections are as easy as,
[xi,yi] = intersections(contourTable.X, contourTable.Y, N_p_rpm_X, Tq_p_Nm_Y);
plot(xi, yi, 'ko')
You can repeat that for the red line.
  댓글 수: 4
Jackson Foley
Jackson Foley 2020년 5월 14일
Amazing, that works! Thank you so much for your help Adam.
Leilane Passos
Leilane Passos 2023년 2월 27일
Hi, is there a way to pick the indeces as well?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2020년 5월 14일
  댓글 수: 2
Jackson Foley
Jackson Foley 2020년 5월 14일
So I was able to get a matrix of intersection points but its outputting 175 values. From my graph I can visually only see 2 for each efficiency contour curve. Am I missing something?
clear
clc
clf()
% Motor data from specification
raw_peak=[0 462;2000 462;4000 462;6000 462;8000 462;10000 462;12000 462;14000 399;16000 315];
raw_cont=[0 440;2000 440;4000 440;6000 440;8000 440;10000 440;12000 440;14000 380;16000 300];
N=linspace(0,16000,60); % [rpm]%
Tq=linspace(0,462, 50); % [Nm]%
N_p_rpm_X=raw_peak(:,1); % [rpm]%
Tq_p_Nm_Y=raw_peak(:,2); % [Nm]%
N_c_rpm_X=raw_cont(:,1); % [rpm]%
Tq_c_Nm_Y=raw_cont(:,2); % [Nm]%
kc=0.1; % [W/Nm^2]%
ki=0.0; % [W/(rad/s)]%
kw=1.0e-5; % [W/(rad/s)^3]%
C=500; % [W]%
effMin=0.89; % [-]%
omega=N*pi/30; % [rad/s]
for i=1:length(omega)
for j=1:length(Tq)
Pout(i,j)=(omega(i)*Tq(j)); % [W]
Ploss(i,j)=kc*Tq(j)^2+ki*omega(i)+kw*omega(i)^3+C; % [W]
end
end
eff=max(effMin,Pout./(Pout+Ploss))*100; % [-]
eff_trans=eff';
V=[70,85,90,91,92,93,94,95,96,97,98,99];
hold on
[C,h]=contour(N,Tq,eff_trans,V);
plot(N_p_rpm_X,Tq_p_Nm_Y,'b','LineWidth', 2);
plot(N_c_rpm_X,Tq_c_Nm_Y,'r','LineWidth', 2);
clabel(C)
contourTable = getContourLineCoordinates(C);
x2=table2array(contourTable(1:end,3))';
y2=table2array(contourTable(1:end,4))';
N_p_rpm_X_new = [N_p_rpm_X, zeros(size(N_p_rpm_X, 1), size(x2', 2)-size(N_p_rpm_X, 2)); zeros(size(x2', 1)-size(N_p_rpm_X, 1), size(x2', 2))]';
N_c_rpm_X_new = [N_c_rpm_X, zeros(size(N_c_rpm_X, 1), size(x2', 2)-size(N_c_rpm_X, 2)); zeros(size(x2', 1)-size(N_c_rpm_X, 1), size(x2', 2))]';
Tq_p_Nm_Y_new = [Tq_p_Nm_Y, zeros(size(Tq_p_Nm_Y, 1), size(y2', 2)-size(Tq_p_Nm_Y, 2)); zeros(size(y2', 1)-size(Tq_p_Nm_Y, 1), size(y2', 2))]';
Tq_c_Nm_Y_new = [Tq_c_Nm_Y, zeros(size(Tq_c_Nm_Y, 1), size(y2', 2)-size(Tq_c_Nm_Y, 2)); zeros(size(y2', 1)-size(Tq_c_Nm_Y, 1), size(y2', 2))]';
Peak_cords=[N_p_rpm_X_new;Tq_p_Nm_Y_new];
Cont_cords=[N_c_rpm_X_new;Tq_c_Nm_Y_new];
Contour_cords=[x2;y2];
P=InterX(Cont_cords,Contour_cords);
hf=gcf();
ha=gca();
xlim([0 16500]);
ylim([0 500]);
grid on;
xlabel('Motor Speed [rpm]');
ylabel('Motor Torque [Nm] & Motor efficiency [%]');
title('Motor Efficiency')
KSSV
KSSV 2020년 5월 14일
You need to run InterX for each contour line and for each line.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by