<p>Generally the <em>values</em> <span class="math-container">$\vec{rx1},\vec{ry1},\vec{rz1}$</span> are themselves vectors. Each with an <span class="math-container">$(x,y,z,w)$</span> take special note of the <span class="math-container">$w$</span> value. The position values would also have <span class="math-container">$(x,y,z,w)$</span> values. The <span class="math-container">$w$</span> value for the vectors would be <span class="math-container">$0$</span> and it would be <span class="math-container">$1$</span> for the position. Together they make up an affine transformation which is a 4x4 matrix.</p>
<p>It sounds like you have the camera matrix already, sometimes called the view matrix. After being set up it generally transforms objects from world space into camera space. Affine transformations are invertible, once inverted they transform in the <em>opposite</em> direction. For example a 4x4 affine transformation matrix that transforms from world space to camera space can be inverted to transform from camera space to world space.</p>
<p>So the transformation formula is simply:</p>
<pre><code>worldtocamera = inverse(cameratoworld)
</code></pre>
<p>Also, this transformation generalizes very nicely. For example the transformation from model to world combined with world to camera is:</p>
<pre><code>modeltocamera = modeltoworld * worldtocamera
</code></pre>
<p>And the reverse is again simply:</p>
<pre><code>cameratomodel = inverse(modeltocamera)
</code></pre>

CC BY-SA 4.0
2023-01-07T18:53:19.190Z
An alternative is, to use quaternions for orientation.
Thomas
CC BY-SA 4.0
2023-01-07T13:48:55.557Z
2023-01-07T13:48:55.557Z
pmw1234
<p>In the world coordinate system, there are objects with rotation values <code>rx1,ry1,rz1</code> and position values <code>px1,py1,pz1</code>.</p>
<p>Similarly, there is a camera in the world coordinate system with rotation values <code>rx2,ry2,rz2</code> and position values <code>px2,py2,pz2</code>.</p>
<p>What formula can be used to convert <code>rx1,ry1,rz1,px1,py1,pz1</code> to the camera coordinate system?</p>
<p>The up vector of the camera is the Y-axis, always oriented toward the object near the world origin.</p>
<p>The camera and the model are supposed to move within the range as shown in the following gif image.
<a href="https://i.sstatic.net/EEgj9.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EEgj9.gif" alt="enter image description here" /></a></p>
<p>I would like to calculate this with Python, but any answers, including mathematical statements, are welcome.</p>

<3d><coordinates>
How to convert from world coordinates to camera coordinates
taichi
# How to convert from world coordinates to camera coordinates

(Asked by: username_0 on 2023-01-06)

In the world coordinate system, there are objects with rotation values `rx1,ry1,rz1` and position values `px1,py1,pz1`.

Similarly, there is a camera in the world coordinate system with rotation values `rx2,ry2,rz2` and position values `px2,py2,pz2`.

What formula can be used to convert `rx1,ry1,rz1,px1,py1,pz1` to the camera coordinate system?

The up vector of the camera is the Y-axis, always oriented toward the object near the world origin.

The camera and the model are supposed to move within the range as shown in the following gif image.
[![enter image description here](https://i.sstatic.net/EEgj9.gif)](https://i.sstatic.net/EEgj9.gif)

I would like to calculate this with Python, but any answers, including mathematical statements, are welcome.

**Tags:** 3d, coordinates


---

## 1 answers

### Answer by username_1 on 2023-01-07. Score: 2 | Accepted answer

Generally the *values* $\vec{rx1},\vec{ry1},\vec{rz1}$ are themselves vectors. Each with an $(x,y,z,w)$ take special note of the $w$ value. The position values would also have $(x,y,z,w)$ values. The $w$ value for the vectors would be $0$ and it would be $1$ for the position. Together they make up an affine transformation which is a 4x4 matrix.

It sounds like you have the camera matrix already, sometimes called the view matrix. After being set up it generally transforms objects from world space into camera space. Affine transformations are invertible, once inverted they transform in the *opposite* direction. For example a 4x4 affine transformation matrix that transforms from world space to camera space can be inverted to transform from camera space to world space.

So the transformation formula is simply:

```
worldtocamera = inverse(cameratoworld)

```

Also, this transformation generalizes very nicely. For example the transformation from model to world combined with world to camera is:

```
modeltocamera = modeltoworld * worldtocamera

```

And the reverse is again simply:

```
cameratomodel = inverse(modeltocamera)

```

> **Comments:**
> **username_2**: An alternative is, to use quaternions for orientation.  

---

