Understanding View Projections
Two Types of Projections
MATLAB® Graphics supports both orthographic and perspective projection types for displaying 3-D graphics. The one you select depends on the type of graphics you are displaying:
orthographic
projects the viewing volume as a rectangular parallelepiped (i.e., a box with six rectangular faces). Relative distance from the camera does not affect the size of objects. This projection type is useful when it is important to maintain the actual size of objects and the angles between objects.perspective
projects the viewing volume as the frustum of a pyramid (a pyramid whose apex has been cut off parallel to the base). Distance causes foreshortening; objects further from the camera appear smaller. This projection type is useful when you want to display realistic views of real objects.
By default, MATLAB displays objects using orthographic projection. You can set the
projection type using the camproj
command.
These pictures show a drawing of a dump truck (created with
patch
) and a surface plot of a mathematical function, both
using orthographic projection.
If you measure the width of the front and rear faces of the box enclosing the dump truck, you'll see they are the same size. This picture looks unnatural because it lacks the apparent perspective you see when looking at real objects with depth. On the other hand, the surface plot accurately indicates the values of the function within rectangular space.
Now look at the same graphics objects with perspective added. The dump truck looks more natural because portions of the truck that are farther from the viewer appear smaller. This projection mimics the way human vision works. The surface plot, on the other hand, looks distorted.
Projection Types and Camera Location
By default, MATLAB adjusts the CameraPosition
,
CameraTarget
, and
CameraViewAngle
properties to point the camera at the center
of the scene and to include all graphics objects in the axes. If you position the
camera so that there are graphics objects behind the camera, the scene displayed can
be affected by both the axes Projection
property and
the figure Renderer
property. The
following summarizes the interactions between projection type and rendering method.
Orthographic | Perspective | |
---|---|---|
OpenGL® |
|
|
Painters | All objects are displayed regardless of
| Not recommended if graphics objects are behind the
|
This diagram illustrates what you see (gray area) when using orthographic projection and OpenGL. Anything in front of the camera is visible.
In perspective projection, you see only what is visible in the cone of the camera view angle.
Painters rendering method is less suited to moving the camera in 3-D space because MATLAB does not clip along the viewing axis. Orthographic projection in painters method results in all objects contained in the scene being visible regardless of the camera position.
Printing 3-D Scenes
The same effects described in the previous section occur in hardcopy output.
You should specify opengl printing explicitly to obtain the results displayed on
the screen (use the -opengl
option with the
print
command).