11
$\begingroup$

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?

$\endgroup$
4
  • 1
    $\begingroup$ 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. $\endgroup$ May 11, 2020 at 1:33
  • 1
    $\begingroup$ Thanks, I went down that rabbit hole too. I should have added that in the question. $\endgroup$
    – Greg Hurst
    May 11, 2020 at 1:54
  • 1
    $\begingroup$ 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 ? $\endgroup$
    – Rojo
    May 11, 2020 at 11:12
  • $\begingroup$ No, I don't think it does. $\endgroup$
    – Greg Hurst
    May 11, 2020 at 11:42

1 Answer 1

1
$\begingroup$

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.