# Why seems the perspective of a 3D plot distorted?

19 views (last 30 days)
Tommes on 18 Jul 2016
Answered: Friedrich on 21 Jul 2016
Hi there,
I am working on building a model of a virtual world (animated simulation) in MATLAB. Therefore, I tried to replicate a simple setting of the virtual world with MATLAB's 3D plotting tools. The following picture is an overlay of my results. The blue plane and the green square are surface plots generated with MATLAB. The checkered road and the squared checkerboard are from the simulated virtual world.
As can be seen clearly, neither the blue plane with the road nor the green square with the checkerboard do accurately match. Virtually, the corresponding objects have the same dimensions. Furthermore, the camera positions are identical as well as directions and vertical field of view.
Since both cameras are placed in a way they are directly targeting the corresponding square (with camera center axis parallel to ground), it looks pretty much the MATLAB view is somehow distorted. That is, the center of the checkerboard is in the center of the window, whereas the center of the green plane is off to the right and the top of its window.
So, am I missing an essential parameter or why do the two views not match? Below is the code to generate my 3D plot in MATLAB.
Any ideas appreciated a lot!
fig = figure;
fig.Units = 'pixels';
fig.Position = [0 1200-900 1440 900];
fig.Resize = 'off';
[X,Y] = meshgrid(0:0.5:100,-2.5:0.5:7.5);
Z = zeros(size(X));
surf(X,Y,Z);
hold on
% draw model of checker board (green square)
[Ysgn Zsgn] = meshgrid(-0.5: 0.5, 2 : 3);
% distance on x-axis 15 m as for the virtual world
Xsgn = ones(size(Zsgn))*15;
surf(Xsgn, Ysgn, Zsgn);
p = gca;
set(gca, 'CameraViewAngle', 47)
daspect(p, [1 1 1])
camproj('perspective')
campos([0,0,2.5])
camtarget([50,0,2.5])
ylim([-2.5 7.5])
zlim([0 5])

Friedrich on 21 Jul 2016
Hi,
I think the reason you are seeing the scene shifted to the right and upwards is because the axes is not positioned in the center of the figure. When I add this line to the code I see a central green square:
% Make the axes contents fill the window
set(gca, 'Position', [0 0 1 1]);
The default axes Position is shifted to allow for tick labels on the left and bottom.