# Calculating the actual angle subtended by each pixel in a display

**URL:** https://discourse.vtk.org/t/calculating-the-actual-angle-subtended-by-each-pixel-in-a-display/9559
**Category:** Support
**Tags:** python
**Created:** [October 10, 2022, 4:48pm UTC](https://discourse.vtk.org/t/calculating-the-actual-angle-subtended-by-each-pixel-in-a-display/9559 "2022-10-10T16:48:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [October 10, 2022, 4:48pm UTC](https://discourse.vtk.org/t/calculating-the-actual-angle-subtended-by-each-pixel-in-a-display/9559/1 "2022-10-10T16:48:08Z")

</div>

This is a follow up to this previous message (see [VtkCamera angular ranges ranges? - Support - VTK](https://discourse.vtk.org/t/vtkcamera-angular-ranges-ranges/9322)). Can the vertical and horizontal angles for each pixel on a display be calculated? How?

Thanks for any help.  
M.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 12, 2022, 3:20am UTC](https://discourse.vtk.org/t/calculating-the-actual-angle-subtended-by-each-pixel-in-a-display/9559/2 "2022-10-12T03:20:33Z")

</div>

The answer is yes, if you know the viewport size in pixels and the camera’s view angle.

```auto
viewport size: w, h
camera view angle: a

```

also define these:

```auto
pixel coords: x,y
pixel angles: theta,phi

```

Coords can be computed from angles as follows:

```nohighlight
x = w/2 + h/2 * tan(theta)/tan(a/2)
y = h/2 + h/2 * tan(phi)/tan(a/2)

```

And angles from coords as follows:

```nohighlight
theta = atan( tan(a/2) * ( 2*x/h - w/h ) )
phi = atan( tan(a/2) * ( 2*y/h - 1 ) )

```

I can give no guarantees on the correctness, this is just a back-of-the-envelope calculation. But the math is fairly straightforward.

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [October 12, 2022, 2:55pm UTC](https://discourse.vtk.org/t/calculating-the-actual-angle-subtended-by-each-pixel-in-a-display/9559/3 "2022-10-12T14:55:39Z")

</div>

Thanks David!

I am not able to follow your derivation well. I take that theta is the horizontal angle subtended by a pixel and phi the vertical one. Correct? The ‘view angle’ is the vertical angle covered by h pixels?

Do you have a sketch? Sorry for the trouble

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 12, 2022, 3:19pm UTC](https://discourse.vtk.org/t/calculating-the-actual-angle-subtended-by-each-pixel-in-a-display/9559/4 "2022-10-12T15:19:31Z")

</div>

Your interpretation of theta, phi, and “view angle” are all correct. I have no figure, but it shouldn’t be hard to picture in your head.

You can derive the relationship from the fact that `y` must be a linear function of `tan(theta)`, plus the constraints that `y=0` when `theta=-a/2` and that `y=h` when `theta=+a/2`.
