Plot vector in a defined line in 3D graph

4 次查看(过去 30 天)
Hi,
I have a n-by-3 matrix independent of x or y but would like to plot each column with n points as 3D plot along a line.
It should basically look like this, would be the y-coordinate limit, the x-coordinate. The three bold lines are the lines along which I'd like to plot the values of my matrix, so column 1 would be n points along line 1, column 2 n points along line 2, column 3 line 3 and their values should be shown in the z-coordinate.I know every value as well as any angle shown in the picture, but can't think of a proper way to display my data along the lines, as well as tilt the y-coordinate by the angle gamma.
The Matrix is independent from x, y and γ, except for the defined position of each value and I'd like to avoid recalculating the position of every single value.
My code for the plot so far:
%variables from prior code
n = 31; m = 3; b_veff = 22; g_valpha = 14; S_SmY = randi(5,n,m ); S_SrY = randi(5,n,m ); S_StY = randi(5,n,m );
%grid for x- and y-axis; y axis should be tilted by angle gamma
[x,y] = meshgrid(0:b_veff/(n-1):b_veff,0:g_valpha/2:g_valpha);
%for-loop for three different cases, unimportant for question
for i = 1 : m
z=[S_SrY(:,i) S_SmY(:,i) S_StY(:,i)]'; % each S_S*Y should be plotted along one line as shown above
figure;
surf(x,y,z)
%%unimportant for issue
ax = gca;
ax.XLabel.String = 'face width';
ax.YLabel.String = 'direction of contact line';
ax.ZLabel.String = 'Safety factor';
caxis([0 3])
title('Local Safety factor, Load Level ',num2str(i));
cmap = interp1(0:1,[1 0 0 ;0 1 0],linspace(0,1,256));
axis equal
colormap(cmap)
colorbar
end
As you can see, I just plotted the columns as three lines parallel to the y-axis, which is no Use to me, but I'm at the end of my wits, so I am grateful for any help whatsoever.
Thank you in advance

回答(1 个)

Binaya
Binaya 2023-9-28
编辑:Binaya 2023-9-29
Hi Arne,
From the posted images, I understand that you want to rotate the lines drawn in the plot on the x-axis by gamma while keeping the z-axis values same.
Please find the below modified code for the plotting the tilted lines in 3D plot:
%variables from prior code
n = 31; m = 3; b_veff = 22; g_valpha = 14; S_SmY = randi(5,n,m ); S_SrY = randi(5,n,m ); S_StY = randi(5,n,m );
%grid for x- and y-axis; y axis should be tilted by angle gamma
[x,y] = meshgrid(0:b_veff/(n-1):b_veff,0:g_valpha/2:g_valpha);
gamma=15 %Angle to be tilted by
gamma = 15
%Rotating the x and y coordinates by gamma angle
x_rotated = x * cosd(gamma) - y * sind(gamma);
y_rotated = x * sind(gamma) + y * cosd(gamma);
%for-loop for three different cases, unimportant for question
for i = 1 : m
z=[S_SrY(:,i) S_SmY(:,i) S_StY(:,i)]'; % each S_S*Y should be plotted along one line as shown above
figure;
%%Plot modified for taking rotated x and y coordinates as input
plot3(x_rotated,y_rotated,z)
%%unimportant for issue
ax = gca;
ax.XLabel.String = 'face width';
ax.YLabel.String = 'direction of contact line';
ax.ZLabel.String = 'Safety factor';
caxis([0 3])
title('Local Safety factor, Load Level ',num2str(i));
cmap = interp1(0:1,[1 0 0 ;0 1 0],linspace(0,1,256));
axis equal
colormap(cmap)
colorbar
end
I hope this helps
Regards
Binaya

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by