简体   繁体   English

2D图像通过垂直于视角的3D绘图

[英]2D Image in 3D plot through Surface perpendicular to viewingangle

so I want to include a 2D figure in a 3D plot and rotate the figure (with view([alpha beta])). 所以我想在3D绘图中包含2D图形并旋转图形(带有视图([alphaβ]))。 As you can imagine, this would distord the surface plot. 你可以想象,这会扰乱表面情节。 So basically I'm trying to figure out, how to adjust the surface plot to become perpendicular to the viewingangle (to see the figure as how it should be) and still being centered at the original location. 所以基本上我想弄清楚,如何调整曲面图以使其垂直于视角(以便看到图形应该如何)并且仍然在原始位置居中。 I found something like 我发现了类似的东西

img = imread('galileo3.png');     % Load a sample image
xImage = [...]   % The x data for the image corners
yImage = [...]             % The y data for the image corners
zImage = [...]   % The z data for the image corners
surf(xImage,yImage,zImage,...    % Plot the surface
     'CData',img,...
     'FaceColor','texturemap');
view([phi theta]);

But what's the meaning of the image corners? 但是图像角落的意义是什么? And how would I adjust the original coordinates, to rotate the surface towards the viewingangle (but still being centered at the original location)? 如何调整原始坐标,将曲面旋转到视角(但仍然在原始位置居中)?

You can use the viewmtx command to determine the proper transformation matrix. 您可以使用viewmtx命令确定正确的转换矩阵。 To make this work, you take all of your X, Y, and Z values and reshape them each into a single row. 为了完成这项工作,您可以获取所有X,Y和Z值,并将它们重新整形为一行。 If your original data doesn't have Z values, set them to zero. 如果原始数据没有Z值,请将它们设置为零。

You have to reshape your transformed coordinates back to their previous shapes in order to use them in 'surf' commands, etc. 您必须将已转换的坐标重新整形回以前的形状,以便在“冲浪”命令等中使用它们。

The transformation matrix is simply a function of the view so you can apply the same transformation to multiple data sets simply by making a new XYZ1 variable and multiplying again. 变换矩阵只是视图的一个函数,因此您只需创建一个新的XYZ1变量并再次相乘即可将相同的变换应用于多个数据集。 That's also handy if you want to make an animation as you circle around a plot. 如果你想围绕一个情节制作动画,这也很方便。 You can just re-apply the transformation. 您可以重新应用转换。

sizeX = size(X); % repeat for Y, Z;
X = reshape(X,1,numel(X)); % repeat for Y, Z;

XYZ1 = [X; Y; Z; ones(size(X))]; % it's important that you make this 4 rows

A = viewmtx(Azimuth, Elevation);
Transformed_XYZ = A * XYZ1; % you must left-multiply by A

X_Transformed = Transformed_XYZ(1,:); % rows 2 and 3 for Y and Z respectively
X_Transformed = reshape(X_transformed, sizeX); % putting X' into the same shape as X - repeat for Y and Z

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM