Common part of 2D and 3D plot

Hi, I have a 3D plot that are plotted based on data (the data attached and shown with blue in the figure below), and a 2d curve on the yz plane. I want to know which part of 2d curve is on the 3d plot. here is the information for the figure:
For 2D plot on the yz: f=0.07.*z.^2./(0.09+z.^2) and g=0.003+0.01.*(42./(42+(y-z).^4)) and I want to plot g-f=0 in yz plane.
and 3D curve has data attached here. for example in this figure that is 3d I want to know where is the 2D curve on the yz plane that I showed. I would appreciate any help
A = importdata(curve3dfinal)

 Risposta accettata

I am not certain what result you want.
It is straightforward to rotate the 3D plot to give a 2D view from the Z-axis —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022280/curve3dfinal.zip');
% type(Uz{1})
C3DF = readmatrix(Uz{1})
C3DF = 30001×3
0.0033 1.2649 0.4327 0.0033 1.2645 0.4327 0.0032 1.2640 0.4326 0.0032 1.2636 0.4326 0.0032 1.2632 0.4325 0.0032 1.2627 0.4325 0.0032 1.2623 0.4324 0.0032 1.2619 0.4323 0.0032 1.2614 0.4322 0.0032 1.2610 0.4321
x = C3DF(:,1);
y = C3DF(:,2);
z = C3DF(:,3);
figure
plot3(x, y, z)
grid on
view(20,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('3D View')
figure
plot3(x, y, z)
grid on
view(0,90)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('View From Z-Axis')
.

13 Commenti

M
M il 5 Giu 2022
Thank you for the answer. Yes I can plot this part but the point is that I want to see which part of the curve below on yz plane hit the 3D plot that I showed on the figure with black square.
g-f=0 ==>> f=0.07.*z.^2./(0.09+z.^2) and g=0.003+0.01.*(42./(42+(y-z).^4)) .
I am not certain that I understand.
Rotating it differently —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022280/curve3dfinal.zip');
% type(Uz{1})
C3DF = readmatrix(Uz{1})
C3DF = 30001×3
0.0033 1.2649 0.4327 0.0033 1.2645 0.4327 0.0032 1.2640 0.4326 0.0032 1.2636 0.4326 0.0032 1.2632 0.4325 0.0032 1.2627 0.4325 0.0032 1.2623 0.4324 0.0032 1.2619 0.4323 0.0032 1.2614 0.4322 0.0032 1.2610 0.4321
x = C3DF(:,1);
y = C3DF(:,2);
z = C3DF(:,3);
figure
plot3(x, y, z)
grid on
view(90,0)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('View From X-Axis')
.
M
M il 5 Giu 2022
I really appreciate your help. Let's clarify what I mean:
The figure includes 2 parts:
  • First, I want a 3D curve based on data, that you plotted it, so this part was done.
  • secondly, I want to plot the below curve in the same figure to see the common part of the 3D curve (plotted in first item) and below curve both in 3D space and in yz plane:
g-f=0 ==>> f=0.07.*z.^2./(0.09+z.^2) and g=0.003+0.01.*(42./(42+(y-z).^4)) .
I am completely lost.
Importing my code fron your other post, I get this result —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022280/curve3dfinal.zip');
% type(Uz{1})
C3DF = readmatrix(Uz{1})
C3DF = 30001×3
0.0033 1.2649 0.4327 0.0033 1.2645 0.4327 0.0032 1.2640 0.4326 0.0032 1.2636 0.4326 0.0032 1.2632 0.4325 0.0032 1.2627 0.4325 0.0032 1.2623 0.4324 0.0032 1.2619 0.4323 0.0032 1.2614 0.4322 0.0032 1.2610 0.4321
x = C3DF(:,1);
y = C3DF(:,2);
z = C3DF(:,3);
% figure
% plot3(x, y, z)
% grid on
% view(90,0)
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
% title('View From X-Axis')
f = @(z) 0.07.*z.^2./(0.09+z.^2);
g = @(y,z) 0.003+0.01.*(42./(42+(y-z).^4));
N = 25;
yv = linspace(0, 0.25, N); % Use 'Curve' Limits
zv = linspace(0, 1.5, N); % Use 'Curve' Limits
[Y,Z] = ndgrid(yv,zv);
% figure
% surf(Y,Z,f(Z))
% colormap(turbo)
%
% figure
% surf(Y,Z,g(Y,Z))
% colormap(turbo)
figure
% surf(g(Y,Z)-f(Z),Y,Z)
hold on
plot3(x, y, z, '-g', 'LineWidth',2)
contour3(Y,Z,g(Y,Z)-f(Z), [0 0], '-r', 'LineWidth',2) % Plot Contour At 0
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
grid on
colormap(turbo)
legend('Curve Data','Contour3', 'Location','best')
% view(90,0)
view(30,30)
.
M
M il 6 Giu 2022
I think there is still a problem that it shows the curve g-f=0 in xy plane while it should be in yz plane. I used the code in the below link and some part of your code, but it said Vectors must be the same length.
Do you know how to solve this part?
I am having a very difficult time conceptualizing this. If the contour needs to be in th (Y,Z) plane, that means it has to be defined as the ‘X’ matrix in the contour3 call, and that yields nothing in the plot because it does not go to 0 in Z and that is required for contour3 as written earlier.at least with respect to the limits defined in the curve in the .zip file.
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022280/curve3dfinal.zip');
% type(Uz{1})
C3DF = readmatrix(Uz{1})
C3DF = 30001×3
0.0033 1.2649 0.4327 0.0033 1.2645 0.4327 0.0032 1.2640 0.4326 0.0032 1.2636 0.4326 0.0032 1.2632 0.4325 0.0032 1.2627 0.4325 0.0032 1.2623 0.4324 0.0032 1.2619 0.4323 0.0032 1.2614 0.4322 0.0032 1.2610 0.4321
x = C3DF(:,1);
y = C3DF(:,2);
z = C3DF(:,3);
% figure
% plot3(x, y, z)
% grid on
% view(90,0)
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
% title('View From X-Axis')
f = @(z) 0.07.*z.^2./(0.09+z.^2);
g = @(y,z) 0.003+0.01.*(42./(42+(y-z).^4));
N = 25;
yv = linspace(0, 0.25, N); % Use 'Curve' Limits
zv = linspace(0, 1.5, N); % Use 'Curve' Limits
[Y,Z] = ndgrid(yv,zv);
% figure
% surf(Y,Z,f(Z))
% colormap(turbo)
%
% figure
% surf(Y,Z,g(Y,Z))
% colormap(turbo)
figure
surf(g(Y,Z)-f(Z),Y,Z)
hold on
plot3(x, y, z, '-g', 'LineWidth',2)
contour3(g(Y,Z)-f(Z),Y,Z, [0 0], '-r', 'LineWidth',2) % Plot Contour At 0
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
grid on
colormap(turbo)
% legend('Curve Data','Contour3', 'Location','best')
% view(90,0)
view(30,30)
I honestly have no idea how this is supposed to work, or what the desired result is. The surface (as it now appears to be defined as the ‘X’ matrix variable in the surf plot) seems to have nothing in common with the curve in thd .zip file.
Unless I can understand how this is suposed to work, I will delete my answer in the next day or two and you can see if someone else has a solution.
.
M
M il 6 Giu 2022
Ok, let's look at this problem from another aspect. In general, If we want to plot a function of y and z (in this format "g-f=0") in the yz plane in 3D figure (as a curve, not a surface), what should we do?
Or can we solve "g-f=0" to become a function of y or z and plot it? (however, I don't know how to do it)
y and z should be positive.
Please ignore this if it takes your time or if I have to post it as a new question. And thank you so much for all of your help and time.
Calculating the contour (or solving the implicit function, essentially the same thing) is not the issue. That we solved in your other post.
The problem I am having is that I have no idea how to incorporate it with the curve given in the .zip file. That appears to be the focus of this thread, and I cannot figure out how to somehow combine the two of them in 3D space (or as 2D projections of some sort), since they appear to have nothing in common.
End of my day here (UCT-6) so I will see if we can resolve this in the morning.
I think the data in the zipped file have nothing to do with the equations provided.
If data points are given, then it is unnecessary to process the equations. Tools are available in MATLAB to project the data points in the desired plane of view.
@M to clarify on this matter.
This is the best I can do —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022280/curve3dfinal.zip');
% type(Uz{1})
C3DF = readmatrix(Uz{1})
C3DF = 30001×3
0.0033 1.2649 0.4327 0.0033 1.2645 0.4327 0.0032 1.2640 0.4326 0.0032 1.2636 0.4326 0.0032 1.2632 0.4325 0.0032 1.2627 0.4325 0.0032 1.2623 0.4324 0.0032 1.2619 0.4323 0.0032 1.2614 0.4322 0.0032 1.2610 0.4321
x = C3DF(:,1);
y = C3DF(:,2);
z = C3DF(:,3);
% figure
% plot3(x, y, z)
% grid on
% view(90,0)
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
% title('View From X-Axis')
f = @(z) 0.07.*z.^2./(0.09+z.^2);
g = @(y,z) 0.003+0.01.*(42./(42+(y-z).^4));
N = 25;
yv = linspace(0, 0.25, N); % Use 'Curve' Limits
zv = linspace(0, 1.5, N); % Use 'Curve' Limits
[Y,Z] = ndgrid(yv,zv);
% figure
% surf(Y,Z,f(Z))
% colormap(turbo)
%
% figure
% surf(Y,Z,g(Y,Z))
% colormap(turbo)
figure
% surf(g(Y,Z)-f(Z),Y,Z)
hold on
plot3(x, y, z, '-g', 'LineWidth',2)
h = fimplicit(@(Z,Y)g(Y,Z)-f(Z), '-r','LineWidth',2);
% contour3(Y, Z, g(Y,Z)-f(Z),Z,[0 0], '-r', 'LineWidth',2) % Plot Contour At 0
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
grid on
colormap(turbo)
legend('Curve Data','Contour', 'Location','best')
% view(90,0)
view(30,30)
This is the best I can do.
Stopping here.
Experiment to get the result you want.
.
Giving it one last try —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022280/curve3dfinal.zip');
% type(Uz{1})
C3DF = readmatrix(Uz{1})
C3DF = 30001×3
0.0033 1.2649 0.4327 0.0033 1.2645 0.4327 0.0032 1.2640 0.4326 0.0032 1.2636 0.4326 0.0032 1.2632 0.4325 0.0032 1.2627 0.4325 0.0032 1.2623 0.4324 0.0032 1.2619 0.4323 0.0032 1.2614 0.4322 0.0032 1.2610 0.4321
x = C3DF(:,1);
y = C3DF(:,2);
z = C3DF(:,3);
% figure
% plot3(x, y, z)
% grid on
% view(90,0)
% xlabel('X')
% ylabel('Y')
% zlabel('Z')
% title('View From X-Axis')
f = @(z) 0.07.*z.^2./(0.09+z.^2);
g = @(y,z) 0.003+0.01.*(42./(42+(y-z).^4));
N = 25;
yv = linspace(min(y), max(y), N); % Use 'Curve' Limits
zv = linspace(min(z), max(z), N); % Use 'Curve' Limits
[Y,Z] = meshgrid(yv,zv);
% figure
% surf(Y,Z,f(Z))
% colormap(turbo)
%
% figure
% surf(Y,Z,g(Y,Z))
% colormap(turbo)
figure
% surf(g(Y,Z)-f(Z),Y,Z)
hold on
hp31 = plot3(x, y, z, '-g', 'LineWidth',2);
h = fimplicit(@(Z,Y)g(Y,Z)-f(Z), 'LineWidth',0.1, 'Color',[1 1 1 0]);
% get(h)
hp32 = plot3(h.ZData, h.YData, h.XData, '-r', 'LineWidth',2);
% contour3(Y, Z, g(Y,Z)-f(Z),Z,[0 0], '-r', 'LineWidth',2) % Plot Contour At 0
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
grid on
colormap(turbo)
axis([0 max(x) 0 max(y) 0 1.1]) % Set Axis limits
legend([hp31,hp32],'Curve Data','Contour', 'Location','best')
% view(90,0)
view(30,30)
This does not show the complete contour, only the part that it has in common with the green loop curve. (To see all of it, comment the axis call.) Change the argument order in the ‘hp32’ plot3 call to get different results.
.
M
M il 7 Giu 2022
Fantastic. Very appreciate...
I removed my comments that are not necessary
As always, my pleasure!
I finally figured it out!

Accedi per commentare.

Più risposte (1)

Sam Chak
Sam Chak il 6 Giu 2022
Modificato: Sam Chak il 6 Giu 2022
HI @M
If the points of the desired function h are projected to the y–z plane, then the curve should look like this:
f = @(z) 0.07*z.^2./(0.09 + z.^2);
g = @(z, y) 0.003 + 0.01*(42./(42 + (y - z).^4));
fcn = @(z, y) g(z, y) - f(z);
fyz = fimplicit(fcn, [-0.15 0.15 -5 5]);
z = fyz.XData;
y = fyz.YData;
plot(y, z, 'linewidth', 1.5)
On 3D, I think the function looks like this:
h = 0.003 + 0.01*(42./(42 + (y - z).^4)) - (0.07*z.^2./(0.09 + z.^2));
plot3(y, z, h, 'linewidth', 1.0)

Community Treasure Hunt

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

Start Hunting!

Translated by