Matlab:在3D图中添加多个3D笛卡尔坐标轴

时间:2018-10-10 15:30:37

标签: matlab matlab-figure

直接回答问题:如何让我的情节看起来像这样: enter image description here

像这样:

enter image description here

其中是右手笛卡尔坐标系(轴标记位于箭头的末尾,例如,在本示例中,x轴标记为= $ x_1 ^ G $)

一些阐述和前言:首先,我是matlab和“矩阵数学”的新手。我尝试在此网站上搜索与上面提出的问题类似的问题,但没有看到任何内容(但我可能错过了),因此希望这不是重复的。

这是我用来开发旋转椭圆体的代码(因为我是Matlab的新手,所以我会对代码有任何评论):

%Insert the components of the 3x3 matrix (i.e. the scalar values of the 2nd-rank symmetric tensor)

Pmatrix = [115.9547 12.03765 4.68235; 12.03765 116.3702 -2.47985; 4.68235 -2.47985 134.5488];

[R,D]=eig(Pmatrix); %find the eigenvectors (R) and eigenvalues (D) of the 2nd-rank tensor

[x, y, z] =sphere; %generate coordinates of a sphere, using the sphere command

%Stretch the coordinates of the sphere to form the tensor's representation ellipsoid, do this by multiplying the x, y, z coordinates by the square-roots of the eigenvalues
x1 = x*sqrt(D(1,1));
y1 = y*sqrt(D(2,2));
z1 = z*sqrt(D(3,3));
figure;
hmesh = mesh(x1,y1,z1);
set(hmesh,'FaceColor',[0.5,0.5,0.5],'FaceAlpha',0.5) %set color to gray, make mostly transparent
axis equal; %Make tick mark increments on all axes equal
xlabel('x');
ylabel('y');
zlabel('z');

theta1 = -asind(R(3,1)); %rotation around y-axis in degrees
psi1 = atan2d(R(3,2)/cos(theta1),R(3,3)/cos(theta1)); %rotation around x-axis in degrees 
phi1 = atan2d(R(2,1)/cos(theta1),R(1,1)/cos(theta1)); %rotation around z-axis in degress

direction = [1 0 0]; %rotate the surface plot psi1 degrees around its x-axis
rotate(hmesh,direction,psi1)
direction = [0 1 0]; %rotate the surface plot theta1 degrees around its y-axis
rotate(hmesh,direction,theta1)
direction = [0 0 1]; %rotate the surface plot phi1 degrees around its z-axis
rotate(hmesh,direction,phi1)

view([-36 18]);  %Change the camera viewpoint

要添加到我的问题,我想在情节中添加其他(类似)项目,以便最终产品看起来像这样:

enter image description here

在上图的开发中,添加了一组与椭球特征向量共线的轴(红色,绿色,蓝色箭头):

enter image description here

然后,这些轴沿相反的方向延伸通过原点,其中这些轴的这些部分以虚线显示:

enter image description here

然后,标记全局坐标轴(黑色箭头)和椭圆轴(彩色箭头)之间的角度,如下所示:

enter image description here

要对最后的添加发表评论,有人用这些功能(see youtube video here)构建了一些matlab代码。在视频的说明中,它说的是Matlab代码can be found here。作为Matlab的新手,我看不到代码在哪里,例如,我看不到此页面上的代码(下面的屏幕截图)是如何建立在youtube视频中看到的Matlab图。如果您可以指导我如何导航该mathworks-fileexchage页面,将不胜感激。

enter image description here

0 个答案:

没有答案