# Use of virtual tangent screen in mworks 0.5.1

**URL:** <https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575>\
**Category:** Support\
**Created:** [June 26, 2014, 8:01am UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575 "2014-06-26T08:01:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 26, 2014, 8:01am UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575/1 "2014-06-26T08:01:04Z")

</div>

Dear developers,

I’m from Zoccolan Lab in SISSA.  
I’m starting to use mworks for a simple electrophysiological experiments with rats, where I need to show some gratings on the screen.  
I’m actually facing a problem with the implementation of the virtual tangent screen: despite having set it on in the setup variables, I actually see no change on the screen.  
Moreover, I would like to know if there is some documentation regarding the calculation mworks makes to set screen degrees from the display size, it would be really helpful.  
Thanks for your support!  
Alessandro

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 27, 2014, 3:47pm UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575/2 "2014-06-27T15:47:44Z")

</div>

Hi Alessandro,

For assistance with the virtual tangent screen, you’ll need to contact Dave Cox. I’m not familiar with Dave’s plans for the feature, but at present it has not been merged in to the main MWorks code base (hence its absence from the 0.5.1 release).

> Moreover, I would like to know if there is some documentation regarding the calculation mworks makes to set screen degrees from the display size

Here’s the calculation that MWorks performs:

```
half_width_deg = (180 / pi) * atan((width / 2) / distance)
half_height_deg = half_width_deg * height / width

left = -half_width_deg
right = half_width_deg
top = half_height_deg
bottom = -half_height_deg

```

Cheers,  
Chris Stawarz

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 28, 2014, 1:32pm UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575/3 "2014-06-28T13:32:48Z")

</div>

Hi Cristopher,  
Thanks for your answers!

Regarding the use of virtual tangent screen, I will contact Dave Cox.

Regarding the calculation of display angles, in my case (a 103x58cm monitor at a distance of 30 cm) I expect a value in degrees of 120x88, but instead mworks is giving me 120x67.  
Can you please explain why the half\_height\_deg is calculated in this way, and not simply by repeating the formula used for half\_width\_deg?  
I assume it has something to do with the aspect ratio of the screen, but I’m not sure.

Thanks for your willingness.  
Alessandro

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 2, 2014, 4:02pm UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575/4 "2014-07-02T16:02:08Z")

</div>

Hi Alessandro,

> Regarding the calculation of display angles, in my case (a 103x58cm monitor at a distance of 30 cm) I expect a value in degrees of 120x88, but instead mworks is giving me 120x67. Can you please explain why the half\_height\_deg is calculated in this way, and not simply by repeating the formula used for half\_width\_deg?

The code that does that calculation predates my involvement with MWorks, so I had to think about it for a while. Here’s how this works:

If the stimulus observer’s eye is at distance _d_ from the center of the display, then the visual angle _V_ subtended by a circle of radius _r_ whose center coincides with that of the display is given (in radians) by

```
V = 2 * atan(r / d)

```

which is basically the equation for `half_width_deg` given above.

Now, the point of these calculations is to define a mapping from degrees of visual angle to display pixels. In order for this mapping to preserve the shapes of stimuli (e.g. so that the aspect ratio of a rectangle does not change when the coordinates of its vertices are converted from degrees to pixels), we need it to be both linear and identical in every direction. Put another way, if a given visual angle is increased by _ΔV_, then the corresponding change in radius _Δr_ should be independent of both _r_ and the direction of the radius vector. More formally, we need the derivative of _r_ with respect to _V_ to be constant.

Rearranging the previous equation to express _r_ as a function of _V_, we get

```
r = d * tan(V / 2)

```

The derivative of this equation is _not_ constant with respect to _V_. However, if _V/2_ is small, then we can apply the [small-angle approximation](http://en.wikipedia.org/wiki/Small-angle_approximation), and the above equation simplifies to

```
r = d * (V / 2)

```

which _does_ have a constant derivative.

Getting back to your question, the above equation yields the following formulas for `half_width_deg` and `half_height_deg`:

```
half_width_deg = (180 / pi) * (width / 2) / distance
half_height_deg = (180 / pi) * (height / 2) / distance

```

Dividing the second equation by the first and multiplying by `half_width_deg` gives

```
half_height_deg = half_width_deg * height / width

```

which is exactly the equation MWorks uses to compute `half_height_deg`.

Now, since we used the small-angle approximation to get to this point, the validity of these results depends on the angle _V_/2 being suitably small. In order to keep the relative error within 2%, _V_/2 must be no larger than about 14 degrees. This implies that the distance from the observer’s eye to the center of the display should be at least twice the display’s largest dimension, i.e.

```
distance >= 2 * max(width, height)

```

In the case of your setup, this relation does _not_ hold, which is why the display dimensions calculated by MWorks differ from what you expect.

The upshot here is that, for your setup, describing positions and sizes in terms of visual angle just isn’t going to be very useful, because those coordinates can’t be mapped on to pixels in a linear fashion. Instead, you’ll need to pick a different coordinate system that _does_ vary linearly with pixels, and then choose values for the width, height, and distance to the display that yield the bounds you want.

In the future, MWorks probably should provide built-in support for alternative coordinate systems. [PsychoPy](http://www.psychopy.org/general/units.html) seems to offer a nice set of unit options, so we may want to follow their lead.

I hope you find this helpful. If you have additional questions, please let me know.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 3, 2014, 8:50am UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575/5 "2014-07-03T08:50:18Z")

</div>

Hi Christopher,

Thanks for your time and your explanation, now everything is clear.  
I will try to find some other way to solve this issue.

Thanks again for your willingness.  
Ale

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 10:59pm UTC](https://mworks.discourse.group/t/use-of-virtual-tangent-screen-in-mworks-0-5-1/575/6 "2022-07-19T22:59:10Z")

</div>


