({{, (RefLink[ViewMatrix, paclet:ref/ViewMatrix])
is an option for (RefLink[Graphics3D, paclet:ref/Graphics3D]) and related functions that can be used to specify a pair of explicit homogeneous transformation and projection matrices for 3D coordinates.}})

OpenersNotesSection(Spacer1)Details

(RefLink[ViewMatrix, paclet:ref/ViewMatrix]) can be set to a pair of 4×4 matrices {t,p}, where t is a homogeneous transformation matrix and p is a projection matrix in 3D.

The transformation matrix t is applied to the list {x,y,z,1} for each point. The projection matrix p is applied to the resulting vectors from the transformation.

If the result is {tx,ty,tz,tw}, then the screen coordinates for each point are taken to be given by {tx,ty}/tw.

With the default setting (RefLink[ViewMatrix, paclet:ref/ViewMatrix])->(RefLink[Automatic, paclet:ref/Automatic]), the matrices {t,p} are found automatically from the settings for options such as (RefLink[ViewPoint, paclet:ref/ViewPoint]), (RefLink[ViewVertical, paclet:ref/ViewVertical]), and (RefLink[ViewAngle, paclet:ref/ViewAngle]).

With the setting (RefLink[ViewMatrix, paclet:ref/ViewMatrix])->(RefLink[Automatic, paclet:ref/Automatic]), explicit forms for the matrix m can be found using (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions])[g,ViewMatrix].

An explicit setting (RefLink[ViewMatrix, paclet:ref/ViewMatrix])->{t,p} overrides settings for (RefLink[ViewVector, paclet:ref/ViewVector]), (RefLink[ViewPoint, paclet:ref/ViewPoint]), and other view options.

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Define a rescaling transform t:

t=TransformationMatrix[RescalingTransform[{{-2,2},{-2,2},{-3/2,5/2}}]]

Define an orthographic projection p from the front:

p={{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};

Display a 3D object using the orthographic view:

Graphics3D[{Cuboid[{-1,-1,-1},{1,1,1}],Sphere[{0,0,1},1]},ViewMatrix->{t,p},Boxed->False,Lighting->{{"Directional",White,{0,-2,0}}}]

Define a transform t that rotates an object 45° around x and z axes, then rescales it:

t=TransformationMatrix[RescalingTransform[{{-2,2},{-2,2},{-2,2}}].RotationTransform[Pi/4,{1,0,0}].RotationTransform[-Pi/4,{0,0,1}]]

Define an orthographic projection p from the negative y direction:

p={{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};

Display a 3D object using the orthographic view:

Graphics3D[{Cuboid[{-1,-1,-1},{1,1,1}],Sphere[{0,0,1},1]},ViewMatrix->{t,p},Boxed->False,Lighting->{{"Directional",White,{0,-2,0}}}]

OpenersExampleSection1(Spacer1)Scope  (2)

Transformation matrices with different rotation angles around the x axis:

t[a_]:=TransformationMatrix[RescalingTransform[{{-2,2},{-2,2},{-2,2}}].RotationTransform[a,{1,0,0}]]

p={{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};

Table[Graphics3D[{Cuboid[{-1,-1,-1},{1,1,1}],Sphere[{0,0,1},1]},ViewMatrix->{t[a],p},Boxed->False,Lighting->{{"Directional",White,{{0,-2,0},{0,0,0}}}}],{a,{0,Pi/6,Pi/4,Pi/3}}]

Orthographic projections from different sides:

t=TransformationMatrix[RescalingTransform[{{-2,2},{-2,2},{-2,2}}]];

p1={{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};
p2={{1,0,0,0},{0,1,0,0},{0,0,-1,0},{0,0,0,1}};
p3={{0,1,0,0},{0,0,1,0},{-1,0,0,0},{0,0,0,1}};

Table[Graphics3D[{Cuboid[{-1,-1,-1},{1,1,1}],Sphere[{0,0,1},1/2],Cylinder[{{1,0,0},{3/2,0,0}},1/2]},ViewMatrix->{t,p},Boxed->False,Lighting->{{"Directional",White,{{2,-2,0},{0,0,0}}}}],{p,{p1,p2,p3}}]

OpenersExampleSection2(Spacer1)Applications  (1)

OpenersExampleSubsection0(Spacer1)Oblique Projection  (1)

Draw a simple 3D bar chart:

g=BarChart3D[{1,2,3,4,5},ColorFunction->"Rainbow",Method->{"Canvas"->None},Axes->False,Boxed->False,FaceGrids->None]

Define a rescaling transform matrix that rescales the bar charts into a unit cube:

tr=TransformationMatrix[RescalingTransform[{{-2,7.5},{0,1},{-2,7}}]];

Define an orthographic view matrix from the front:

p={{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};

Define an oblique projection matrix with an angle t and a scaling factor s:

oblique[t_,s_]:={{1,0,s Cos[t],0},{0,1,s Sin[t],0},{0,0,1,0},{0,0,0,1}};

Display the projected bar chart:

Manipulate[Show[g,ViewMatrix->{tr,oblique[t,s].p}],{{t,Pi/4},-Pi,Pi},{{s,1/10},0,1/5},SaveDefinitions->True]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

Define a transformation function with rotations and rescaling:

tf=RescalingTransform[{{-2,2},{-2,2},{-2,2}}].RotationTransform[Pi/4,{1,0,0}].RotationTransform[-Pi/4,{0,0,1}]

Define an orthographic projection matrix from the front:

p={{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};

Show the orthographic view with lighting from the front to the center, using (RefLink[ViewMatrix, paclet:ref/ViewMatrix]):

Graphics3D[{Cuboid[{-1,-1,-1},{1,1,1}],Sphere[{0,0,1},1]},ViewMatrix->{TransformationMatrix[tf],p},Boxed->False,Lighting->{{"Directional",White,{{0,-2,0},{0,0,0}}}}]

The same result can be achieved by using an explicit (RefLink[ViewPoint, paclet:ref/ViewPoint]) and transforming 3D objects and lighting:

Graphics3D[GeometricTransformation[{Cuboid[{-1,-1,-1},{1,1,1}],Sphere[{0,0,1},1]},tf],ViewPoint->{0,-Infinity,0},PlotRange->{{0,1},{0,1},{0,1}},Boxed->False,Lighting->{{"Directional",White,tf[{0,-2,0}]}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[TransformationMatrix, paclet:ref/TransformationMatrix])  ▪  (RefLink[ViewVector, paclet:ref/ViewVector])  ▪  (RefLink[ViewPoint, paclet:ref/ViewPoint])  ▪  (RefLink[ViewCenter, paclet:ref/ViewCenter])  ▪  (RefLink[ViewVertical, paclet:ref/ViewVertical])  ▪  (RefLink[ViewAngle, paclet:ref/ViewAngle])  ▪  (RefLink[ViewRange, paclet:ref/ViewRange])  ▪  (RefLink[ViewProjection, paclet:ref/ViewProjection])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[3D Graphics Options, paclet:guide/3DGraphicsOptions])}, {▪(RefLinkPlain[Graphics Coordinates, paclet:guide/GraphicsCoordinates])}})}})