Find Intersection coordinates of Contour and line plot

47 ビュー (過去 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 Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by