Complex literals (was Re: I am never going to complain about Python again)

John Nagle nagle at animats.com
Wed Oct 16 01:27:34 EDT 2013


On 10/10/2013 6:27 PM, Steven D'Aprano wrote:
> For what it's worth, there is no three-dimensional extension to complex 
> numbers, but there is a four-dimensional one, the quaternions or 
> hypercomplex numbers. They look like 1 + 2i + 3j + 4k, where i, j and k 
> are all distinct but i**2 == j**2 == k**2 == -1. Quaternions had a brief 
> period of popularity during the late 19th century but fell out of 
> popularity in the 20th. In recent years, they're making something of a 
> comeback, as using quaternions for calculating rotations is more 
> numerically stable than traditional matrix calculations.

    I've done considerable work with quaternions in physics engines
for simulation.  Nobody in that area calls them "hypercomplex numbers".
The geometric concept is simple.  Consider an angle represented
as a 2-element unit vector.  It's a convenient angle representation.
It's homogeneous - there's no special case at 0 degrees.

    Then upgrade to 3D.  You can represent latitude and longitude
as a 3-element unit vector.  (GPS systems do this; latitude and
longitude are only generated at the end, for output.)

    Then upgrade to 4D.  Now you have a 4-element unit vector
that represents latitude, longitude, and heading. It can
also be thought of as a point on the surface of a 4D sphere,
although that isn't too useful.

    If you have to numerically integrate torques to get
angular velocity, and angular velocity to get angular position,
quaternions are the way to go.  If you want to understand
all this, there's a good writeup in one of the Graphics Gems
books.

    Unlike complex numbers, these quaternions are always unit vectors.

				John Nagle



More information about the Python-list mailing list