Maths - Quaternions

logo back up home forward   further reading more topics »

Maths - Quaternions

This page is an introduction to Quaternions, the pages below this have more detail about their algebra and how to use them to represent 3D rotations.

Introduction

Quaternions were discovered on 16 October 1843 by William Rowan Hamilton. He spent years trying to find a three dimensional number systems, but with no success, when he looked in 4 dimensions instead of 3 it worked.

Quaternions form an interesting algebra where each object contains 4 scalar variables (sometimes known as Euler Parameters not to be confused with Euler angles), these objects can be added and multiplied as a single unit in a similar way to the usual algebra of numbers. However, there is a difference, unlike the algebra of scalar numbers qa * qb is not necessarily equal to qb * qa (where qa and qb are quaternions). In mathematical terms, quaternion multiplication is not commutative.

The arithmetic of quaternions, such as how to do addition and multiplication, is explained on this page.

On this page we will introduce quaternions as an extension of complex numbers with two additional imaginary dimensions, however there are other ways to think about quaternions and other notations for quaternions which are described on this page.

Quaternions have 4 dimensions (each quaternion consists of 4 scalar numbers), one real dimension and 3 imaginary dimensions. Each of these imaginary dimensions has a unit value of the square root of -1, but they are different square roots of -1 all mutually perpendicular to each other, known as i,j and k. So a quaternion can be represented as follows:

a + i b + j c + k d

It may seem strange that there are 3 square roots of -1, but we have to remember that we are working in 4 dimensions so there are at least 3 ways to get round from +1 to -1. It is not very practical to try to draw 4 dimensions in 2 dimensions, but here is an attempt:

We have to be very careful with this picture of quaternions, it gives an intuative feel for how quaternions can represent rotations in 3D but it is misleading, we might think from this (as Hamilton did) that since i² =-1 that therefore i² represents a rotation of 180° and so 'i' represents a rotation of 90°. This is wrong! As we shall see below, to make it work porperly, we need to halve the angle so 'i' represents a rotation of 180° and i² represents a rotation of 360°. So +1 and -1 both represent the same rotation, this will be explained more fully later.

Use of quaternions to represent transformations in 3D.

The main practical application of this interesting algebra is to represent 3D rotations.

In fact quaternions can represent 3D reflections, rotations and scaling, however a single quaternion operation cannot include translations so if we want to rotate, reflect or scale around a point other than the origin, then we would have to handle the translation part separately (see affine translations). To calculate the resulting point (Pout) when we translate the point (Pin) using quaternions then we use the following equations:

  • For Reflection & scaling: Pout = q * Pin * q
  • For Rotation & scaling: Pout = q * Pin * conj(q)

This is explained further on this page.

The majority of applications involve pure rotations, for this we restrict the quaternions to those with unit magnitude and we use only multiplications and not addition to represent a combination of different rotations. When quaternions are normalised in this way, together with the multiplication operation to combine rotations, form a mathematical group, in this case SU(2).

We can use this to do lots of operations which are required in practical applications such as, combining subsequent rotations (and equivalently orientations), interpolating between them, etc.

When quaternions are used in this way we can think of them as being similar to axis-angle except that real part is equal to cos(angle/2) and the complex part is made up of the axis vector times sin(angle/2). It is quite difficult to give a physical meaning to a quaternion, and many people find this similarity to axis-angle as the most intuitive way to think about it, others may just prefer to think of quaternions as an interesting mathematical system which has the same properties as 3D rotations.

The quaternion in terms of axis-angle is:

q = cos(a/2) + i ( x * sin(a/2)) + j (y * sin(a/2)) + k ( z * sin(a/2))

where:

  • a=angle of rotation.
  • x,y,z = vector representing axis of rotation.

So it is closely related to the axis angle representation of rotations.

 complex numberquaternion number
can be used to represent:2D vector3D rotation
subsequent operations:combined by additioncombined by multiplication
'i' represents:rotation by 90 degreesrotation by 180 degrees
   

The quaternion 'i' represents a rotation of 180 degrees about the x axis, the quaternion 'j' represents a rotation of 180 degrees about the y axis, the quaternion 'k' represents a rotation of 180 degrees about the y axis. So i*i = -1 represents a rotation of 360 degrees about the x axis.

It may seem strange that -1 represents a rotation of 360 degrees, since this is 'no change' I would expect it to be 1.

However it turns out that if (a + b i + c j + d k) represents a rotation then (- a - b i - c j - d k) represents the same rotation. In other words if we negate all the terms we get a different quaternion but it represents the same rotation. This makes sense in terms of axis angle representation, if we take the reverse angle and also reverse the axis this will produce the same result.

So both 1 and -1 represent the identity (do nothing) rotation. An object which, if rotated by 360 degrees it is inverted, is known as a spinor.

Quaternions are therefore spinors.

Why do we need 4 dimensions to represent 3D rotations?

We can represent 3D rotations as 3 numbers (see euler angles) but such a representation is non-linear and difficult to work with. An analogy is a two dimensional map of the earth, there is no way that we can map the surface of the earth without distorting either angles or areas. However once the 2D map is wrapped round a 3D sphere it becomes linear, in a similar way the 3D space of rotations becomes linear when it is mapped to a 4D hypersphere. I have described this analogy further on this page.

There are few differences in this case for instance:

  • We only need half the hypersphere (hyper-hemisphere?) since opposite sides of the hypersphere represent the same rotation.
  • Transforms are combined by multiplying quaternions, not by adding them.
  • Points are transformed by the sandwich product described above.

sfrotation

On these pages will be developing a class sfrotation (full listing here) which holds a rotation and encapsulates operations such as combining two rotations, in addition to coding the rotation as a quaternion it can also be coded as euler or axis angle and can convert between these formats.

Index


Further Reading

You may be interested in other means to represent orientation and rotational quantities such as:

Or you may be interested in how these quantities are used to simulate physical objects:


metadata block
see also:
Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover us uk de jp fr ca On Quaternions and Octonions

cover us uk de jp fr caVisualizing Quaternions by Andrew J. Hanson

Other Math Books

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to the software project, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

cover       LEGO Mindstorms NXT - Allows you to build a robot and program it from a PC or Mac. Contains an Intelligent Brick with 32-bit microprocessor, memory and FLASH, 3 Interactive Servo motors with built-in rotation sensors, sound sensor, ultrasonic sensor, touch sensor, light sensor, USB 2.0 and Bluetooth support. Icon-based drag-and-drop program "building" environment.

Terminology and Notation

Specific to this page here:

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2013 Martin John Baker - All rights reserved - privacy policy.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在TouchDesigner中,你可以使用CHOP(通道操作)节点中的LFO(低频振荡器)和Maths(数学)节点来控制图像。以下是一个简单的例子: 1. 创建一个Movie File In节点,将其命名为“movie_in”。 2. 将Movie File In节点的输出连接到一个常规的TOP(图像处理)节点。 3. 创建一个LFO CHOP节点,并将其命名为“lfo”。 4. 在LFO CHOP节点的参数页面上,设置“Frequency”参数为适当的值,以控制LFO的速度。 5. 创建一个Maths CHOP节点,并将其命名为“maths”。 6. 在Maths CHOP节点的参数页面上,选择“Add”操作,并将其输入连接到“lfo”节点的输出。 7. 在Maths CHOP节点的参数页面上,设置“Value 1”参数为1,以控制LFO的振幅。 8. 创建一个Constant CHOP节点,并将其命名为“constant”。 9. 在Constant CHOP节点的参数页面上,设置“Value”参数为0.5,以控制图像的亮度。 10. 创建一个Maths CHOP节点,并将其命名为“maths2”。 11. 在Maths CHOP节点的参数页面上,选择“Multiply”操作,并将其输入连接到“constant”节点的输出。 12. 将“maths”节点的输出连接到“maths2”节点的第一个输入。 13. 将TOP节点的亮度参数连接到“maths2”节点的输出。 现在,你可以控制图像的亮度,以及LFO的速度和振幅,来创建一个动态的图像效果。你可以通过调整LFO节点和Maths节点的参数来实现不同的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值