[vtk-developers] set Camera parameters from 4x4 matrix

David Gobbi david.gobbi at gmail.com
Sun Apr 27 15:49:42 EDT 2014


Hi Paolo,

Some of those values can be pulled directly from the inverse of the
camera matrix, but others (like the focal point) are impossible to get.

If "c" is a vtkCamera, then you can get the inverse of its matrix like this:

m = vtk.vtkMatrix4x4()
m.DeepCopy(c.GetViewTransformMatrix())
m.Invert()
print m
vtkMatrix4x4 (0x7fbc11608b40)
  Debug: Off
  Modified Time: 206
  Reference Count: 1
  Registered Events: (none)
  Elements:
    0.101219 0.993924 -0.0432312 -3
    -0.989702 0.10502 0.0972703 2
    0.101219 0.0329404 0.994319 100
    -0 0 -0 1

Each column of this inverted matrix has a specific meaning.
The 4th column (-3,2,100) is the position.
The 3rd column (-0.0432312,0.0972703,0.994319) is a unit vector
that points from the focal point towards the camera.
The 2nd column is the view up vector.
The 1st column is the view left vector, and it is always the cross
product of the 2nd and 3rd columns.

It's impossible to get the focal point from the matrix unless you know
the distance of the focal point from the camera.  It's also impossible
to get the viewing angle (you would need to get it from the camera's
projection transform, and I don't have an example for that).

  - David


On Sun, Apr 27, 2014 at 9:50 AM, Shayan Ravaynia <paoloshayan at alice.it> wrote:
> Hi,
>
>
> If have a 4x4 matrix that describes rotation and translation of the camera
> then how can I compute the camera position, focal point, up vector, and
> viewing angle parameters from the matrix ?
> Please if is possible write here a small example ! I'm using Python code.
>
> thanks
>
> Paolo



More information about the vtk-developers mailing list