Difference between revisions of "Coordinate systems"
Line 61: | Line 61: | ||
===consistency check=== | ===consistency check=== | ||
− | There is an extra constraint | + | There is an extra constraint on azimuth and elevation: |
<pre> | <pre> | ||
azimuth + elevation <= pi | azimuth + elevation <= pi |
Revision as of 13:49, 5 March 2024
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)
N.B. The right hand rule does apply: S is outer product of (R, A).
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° <= Azimuth <= 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 -1 for a point in the backward hemisphere.
consistency check
There is an extra constraint on azimuth and elevation:
azimuth + elevation <= pi
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.
- It is good practice that angles in conversion functions between Cartesian coordinates and polar, double polar or spherical coordinates are expressed in radians.
- When expressing angles in degrees is necessary use the following matlab conversion functions:
angle_rad = function deg2rad(angle_deg) angle_deg = function rad2deg(angle_rad)
Coordinate system representations
In our programs all coordinate variables should be listed as a struct of column arrays or as tables.
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 or -1: stands for forward or backward hemisphere)
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)
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.
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....