MATLAB: Find Intersection coordinates of Contour and line plot

contourcoordinatesgetcontourlinecoordinatesintersection

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')

Best Answer

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.
Related Question