# Extract ViewVertical from ViewMatrix

Given a ViewMatrix setting of the form {t, p}, how can one determine the ViewVertical?

Let's say we have

vm = {
{
{0.10402567469787839, 0.05634724046135078, 0., 0.06671318616834762},
{-0.033304268882567746, 0.061484804090894324, 0.09542953968274223, -0.10079092470343654},
{0.045451481623891156, -0.08391042761333754, 0.06992535634444795, -0.030220722382910785},
{0., 0., 0., 1.}
},
{{1., 0., 0., 0.5}, {0., 1., 0., 0.5}, {0., 0., -1, -0.5}, {0., 0., 0., 1.}}
};


The (normalized) ViewPoint can be found with

qr = QRDecomposition[vm[[1]]];

vpn = Sign[Diagonal[qr[[2, 1 ;; 3, 1 ;; 3]]]] qr[[1, 1 ;; 3, 3]]

{0.384185, -0.709265, 0.591054}

Norm[{1.3, -2.4, 2}] * vpn

{1.3, -2.4, 2.}


Can the ViewVertical be found in a similar fashion?

• From Heike's formulae from here, one could use EulerAngles[] to recover rotation angles, but retrieving ViewVertical from those does not look immediately obvious to me. May 11, 2020 at 1:33
• Thanks, I went down that rabbit hole too. I should have added that in the question. May 11, 2020 at 1:54
• I'm not sure how to check, and given the time since you asked, bounty and all, I'm assuming the obvious doesn't work, right? Inverse[vm[[1]]].{0, 1, 0, 0} // Most ?
– Rojo
May 11, 2020 at 11:12
• No, I don't think it does. May 11, 2020 at 11:42

May be this code could be supportive

vm = {{{0.10402567469787839, 0.05634724046135078, 0.,
0.06671318616834762}, {-0.033304268882567746,
0.061484804090894324,
0.09542953968274223, -0.10079092470343654}, \
{0.045451481623891156, -0.08391042761333754,
0.06992535634444795, -0.030220722382910785}, {0., 0., 0.,
1.}}, {{1., 0., 0., 0.5}, {0., 1., 0., 0.5}, {0.,
0., -1, -0.5}, {0., 0., 0., 1.}}};


Let define some function

gvm = Graphics3D[{Opacity[.3], Sphere[]}, ViewMatrix -> vm]


To get point we simply use

AbsoluteOptions[gvm, ViewPoint]

Out[]= {ViewPoint -> {1.3, -2.4, 2.}}


We see that result exactly the same what you calculated. Now we can get vertical as follows

AbsoluteOptions[gvm, ViewVertical]

Out[]= {ViewVertical -> {0., 0., 1.}}

• It looks like AbsoluteOptions is just returning the default values. The same results are returned for the examples in the ViewMatrix reference page. May 13, 2020 at 15:26
• @ChipHurst So you think it is not ViewVertical as it suggested in vm? May 13, 2020 at 16:45
• In this case they agree, but for any vm this will always return {0., 0., 1.}. May 13, 2020 at 16:53
• @ChipHurst It looks like option ViewVertical -> {0., 0., 1.} is default option for any ViewMatrix->{t, p}. May 13, 2020 at 19:01