Coordinate systems

From biophysics
Jump to navigation Jump to search

Introduction

In the three dimensions of our world you can define different coordinate systems. In our auditory labs a subject is placed with his head in the center of the speaker setup (a sphere or semi-circle). We define all coordinate systems with respect to the default position of the head of the subject. Normally we are interested in the direction of a stimulus and we define the directions with the angles azimuth and elevation in a double polar coordinate system. This system is a non-conventional coordinate system that is not used often beyond auditory experiments.

  • When we want to use a Cartesian-like coordinate system for head tracking we will adopt the medical terminology (see next paragraph).
  • With head tracking the coordinates are expressed with respect to the default gaze position in the experiment.
  • Positions of target stimuli are by default expressed in double polar coordinates.
  • Our EMF head tracking system uses three orthogonal axis: Horizontal, Frontal, Vertical. We refer to them as H, F and V.
  • Equipment with IMU's can have use different definitions for Cartesian coordinates. In case of head trackers they have to be converted to the medical coordinate system.
  • We will have no fixed Cartesian coordinate system referred to by X, Y and Z in our lab. They can be defined at will.
  • Use of and transformations between coordinate systems should be made explicit in all documentation and programs.

The Spherical Coordinate System is more standard and is widely used. When your are interested in the Spherical coordinate system you have to ask Wikipedia or other sources.

Cartesian/Body coordinates

Cartesian coordinates in 3 dimensions are normally described by triples (X,Y,Z). For a body (or head) a medical notation is often used:

left (L) 
right (R)
anterior (A)
posterior (P)
superior (S)
inferior (I)

For describing the position of the head of a person we will adopt the 'RAS' convention that is most commonly used by medical applications:

R-axis: from left (-R) to right (+R)
A-axis: from back (-A) to front (+A)
S-axis: from bottom (-S) to top (+S)

In terms of unit vectors: S-hat is outer product of (R-hat, A-hat).

Head tracking coordinates

The convention for head tracking coordinates (H,V,F) is equal to body coordinates:

Horizontal: H = R positive signal when looking right Vertical: V = S positive signal when looking up Frontal: F = A positive signal when looking forward

Due to historical reasons the order of corresponding directions in the triples do not match ([H,V,F] vs [R,A,S]).

Double Polar coordinates

The double polar coordinates are called azimuth , elevation and radius. The azimuth defines a semi-circle parallel to the AS plane. The elevation defines a circle parallel to the RA plane. The intersection of the azimuth circle and the elevation circle is the target point. Since there are two intersections (most of the time), the hemisphere of the intersection has to be specified in order to resolve the ambiguity.

azimuth

  • Azimuth is the angle with the AS plane.
  • pi/2 <= azimuth <= pi/2 (or -90° <= azimuth <= 90°)

elevation

  • Elevation is the angle with the RA plane
  • pi/2 <= elevation<= pi/2 (or -90° <= elevation <= 90°)

radius

  • Radius is the distance from the origin to a target point

hemisphere

  • Hemisphere is +1 for a point in the forward hemisphere.
  • Hemisphere is 0 for a point in the RS-plane (A=0).
  • Hemisphere is -1 for a point in the backward hemisphere.

consistency check

There is a constraint on azimuth and elevation:

azimuth + elevation <= pi (or azimuth + elevation <= 90°)

Transforming double polar to RAS coordinates

right    = radius * sin(azimuth)
superior = radius * sin(elevation)
anterior = hemisphere * sqrt(radius^2 - Right^2 - Superior^2)

Transforming Cartesian to double polar coordinates

In the origin we have by definition azimuth = 0 and elevation = 0.

radius     = norm([right,anterior,superior])
azimuth    = arcsin(right   /radius)    
elevation  = arcsin(superior/radius)
hemisphere = sign(anterior);

Conventions for expressing angles

An angle is normally expressed in radians or degrees.

One radian corresponds to the angle for which the arc (s) on a circle equals the radius (r), thus 1 rad = s/r = 1. In the SI standard 1 rad = 1 per definition, so rad is dimensionless. Therefore it is not necessary to explicitly use it. Only when confusion is possible you should mention it as the unit behind a value.

The other convention for angles is the degree. The conversion between radians and degrees follows from the relation 360° = 2π rad. Note that the degree, with the symbol °, is not a unit of the SI. When expressing angles in degrees the use of the symbol ° is mandatory.

Angles in Matlab

All trigonometry functions in Matlab use radians as unit for angles. Inside your programs it is advised to use only radians in the code and convert to degrees when presenting values for angles on screen, or in an output file. When reading from screen or input file you should convert degrees to radians at the first assignment.

  • When variables use degrees they should have the suffix _deg in the name.
  • It is recommended to use the matlab conversion functions between radians and degrees:
angle     = function deg2rad(angle_deg)
angle_deg = function rad2deg(angle)

Angles in text

When using trigonometric formulae you have to be aware that by default these functions use radians. If you want to use constants expressed in degrees you have to use the degree symbol °. The following expression are equivalent:

X and L in meters, angle in radians

   X = L * sin(pi/2) 

is equivalent to: 

   X = L * sin(90°)

and

   angle = pi   + arcsin(Y/L) 

is equivalent to:
 
   angle = 180° + arcsin(Y/L) 

Coordinate system representations in Matlab

In the Gitlab in biofysica\utilities\coordinates\RAS_DP_SPH there are classes for the coordinates

coordinates_doublePolar.m
coordinates_doublePolar_withID.m
coordinates_RAS.m
coordinates_RAS_withID.m
coordinates_spherical.m
coordinates_spherical_withID.m

and conversion functions between coordinates:

transform_DP2RAS.m
transform_DP2SPH.m
transform_RAS2DP.m
transform_RAS2SPH.m
transform_SPH2DP.m
transform_SPH2RAS.m

RAS coordinates is the standard for coordinates relative to body or head orientation. It has the following fields:

   - ID (optional)
   - right (in meters)
   - anterior (in meters)
   - superior (in meters)

In our auditory experiments the default head position is the reference orientation and the origin is taken between the ears of the subject.

Double Polar coordinates is our standard for auditory perception experiments:

   - ID (optional)
   - azimuth (in radians)
   - elevation (in radians)
   - radius (in meters)
   - hemisphere (+1, 0 or -1: stands for forward or backward hemisphere or in between)

Spherical coordinates is following the Matlab definition:

   - ID (optional)
   - azimuth (in radians: 0 to 2pi positive X-axis is 0)
   - elevation (in radians: -pi to pi positive Y-axis is 0)
   - radius (in meters)

Field coil coordinates is our standard for our field coil head movement detection

   - horizontal (in Volt)
   - vertical (in Volt)
   - frontal (in Volt)

Coordinate transformations

The biofysica repository has the following transformation functions:

  • DP2RAS (Double Polar to RAS)
  • RAS2DP (RAS to Double Polar)
  • sph2RAS (Spherical to RAS)
  • RAS2sph (RAS to Spherical)
  • DP2sph (Double Polar to Spherical)
  • sph2DP (Spherical to Double Polar)

They all have a single input parameter in the form of a struct or table and a single output parameter in the form of a table. Angles are always in radians.

  • HVF2DP_withNetCalibrationFile (Field coil reading to Double Polar)

The HVF2DP has an extra parameter NetCalibrationFile, that should contains the filename of the latest calibration.


Older functions that are using different conventions are (angles in degrees):

varargout = azel2cart(AZ,EL,R)
azel      = xyz2azel(x,y,z)

N.B. These are not recommended for new code.

Stimulus position lookup tables

Setups with different speaker and led positions have a lookup table for the stimulus positions in the form of an excel file. The excel file should have a sheet with the name 'DP' for data in double polar coordinates. The sheet should have five columns with the headers 'ID', 'azimuth', 'elevation', 'radius', 'hemisphere'.

stimulusPos = readtable(fname, 'sheet',  'DP');

The function 'readtable' outputs a table with the named column headers that are accessable in the same way as fields of a struct.

ID = stimulusPos.ID;
azimuth = stimulusPos.azimuth;
etc....