# Obtaining/Creating 4x4 Transformation matrix to the location of a vtkMRMLCameraNode

**URL:** https://discourse.slicer.org/t/obtaining-creating-4x4-transformation-matrix-to-the-location-of-a-vtkmrmlcameranode/29461
**Category:** Development
**Tags:** python
**Created:** [May 14, 2023, 1:52pm UTC](https://discourse.slicer.org/t/obtaining-creating-4x4-transformation-matrix-to-the-location-of-a-vtkmrmlcameranode/29461 "2023-05-14T13:52:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![akumar81](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/akumar81/32/65983_2.png) [@akumar81](https://discourse.slicer.org/u/akumar81)
#### Post date: [May 14, 2023, 1:52pm UTC](https://discourse.slicer.org/t/obtaining-creating-4x4-transformation-matrix-to-the-location-of-a-vtkmrmlcameranode/29461/1 "2023-05-14T13:52:42Z")

</div>

I’m currently working on a project where I control the position of a `vtkCameraNode` in 3D view with a robotic arm. To achieve this, I’ve been placing the camera node on top of a transform like so:

```python

camera_node.SetNodeReferenceID("transform", transform_for_the_camera.GetID())

```

With this method, I can successfully move the camera and retrieve the position of the camera using `GetAppliedTransform()`. Here is an example of the output:

```python

print(stereo.camera_node2.GetAppliedTransform())

```

Output:

```yaml

vtkMatrix4x4 (0x564de95445d0)
  Debug: Off
  Modified Time: 2695454
  Reference Count: 2
  Registered Events: (none)
  Elements:
    -0.0177592 0.999842 7.34635e-06 -0.000133888 
    0.00592044 9.78115e-05 0.999982 -36.4499 
    0.999825 0.0177589 -0.00592124 -12.88 
    0 0 0 1 

```

However, I have a couple of challenges that I need help with. Can I either? :

**1. Is there a way to obtain the transformation to the camera\_node before SetNodeReferenceID(“transform”, transform\_for\_the\_camera.GetID()) is used?**

**OR**

**2. Is it possible to reconstruct the AppliedTransform using available functions like GetViewUp() and GetPosition()?**

To illustrate the second point, here are the outputs of these functions:

```python

print(stereo.camera_node2.GetViewUp()) # view_up
print(stereo.camera_node2.GetPosition()) # position
print(stereo.camera_node2.GetFocalPoint()) # focal_point

```

Output:

```scss

(7.346345810766298e-06, 0.9999824692637288, -0.005921242373602143) # view_up
(-0.00013388794915210472, -36.4498973704036, -12.879999999811874) # position
(-1.2295649116714942, -86.05915036780942, 10.081280602927164) # focal_point

```

In the **`AppliedTransform` 4x4 matrix, the `view_up` vector matches the third column and `position` matches the fourth column.** I attempted to reconstruct the first or second column using `(focal_point - position)/norm(focal_point - position)` _but the results do not match the values in the matrix._

I would greatly appreciate any guidance or suggestions. Thanks in advance for your time and help!

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [May 14, 2023, 1:56pm UTC](https://discourse.slicer.org/t/obtaining-creating-4x4-transformation-matrix-to-the-location-of-a-vtkmrmlcameranode/29461/2 "2023-05-14T13:56:03Z")

</div>

I would recommend to use the [Viewpoint](https://github.com/SlicerIGT/SlicerIGT#viewpoint) module in SlicerIGT extension for positioning a camera with a transform. It allows you to directly set the relative transform between the driving transform and the camera.
