Home > Software engineering >  Adjust projection of 3d plot in Matlab
Adjust projection of 3d plot in Matlab

Time:12-22

Matlab doesn't have an easy off-the-shelf way to adjust the distortion of the projection's perspective of a 3D figure that I know of. So, given the code below:

figure;
x1 = rand(1,10);
x2 = rand(1,10);
x3 = rand(1,10);
scatter3(x1,x2,x3,80,'o','filled'); hold on
ax = gca;
ax.Projection='perspective';

the results is unimpressive:

enter image description here

I tried modifying ax.CameraTarget, the ax.CameraPosition, etc. but the it's nearly impossible to modify the "vanishing point" to look more distorted, e.g. like this: enter image description here

Any help as to how to achieve this level of control on the figure appearance?

thanks!

CodePudding user response:

You can achieve this by moving into the "wide angle" regime, i.e. choosing a large CameraViewAngle while moving the camera further towards the plot. That gives you quite some distortion, like you might know from wide angle camera lenses.

In the following code, I assumed that the camera is placed at the center z-level of the coordinate system and x and y-coordinates are displaced just at the connection line between two edge points of the coordinate system being back-shifted by its length. The rest is basically "law of cosines". Feel free to adapt the camera position within the given sensible levels, such that the view angle remains in the range between 0 and 180 degrees, Sketch of lengths and points that are used in the matlab code

  • Related