Functions of a quaternion variable in the 1456 object code system.

William Overington

Copyright 2001 William Overington

In implementing the manipulation of quaternions in the 1456 object code system I have added a number of commands to the 1456 object code specification. Each of these commands is expressed using two characters, the first character of the pair being either a Q character or a u character. At the time of adding of those commands I realized that it would be possible to include functions of a quaternion variable in the 1456 object code system. At that time I felt that such inclusion would be somewhat extreme and in any case I did not know how to compute them. In any case, I reasoned, should anyone need functions of a quaternion variable then these could be achieved using software interrupts with a specially prepared 1456 applet landscape specifically designed to have facilities for computing functions of a quaternion variable.

However, I have now become aware of an entirely practical application of the logarithm of a quaternion variable and the exponential of a quaternion variable. This is in the smoothing of a rotation.

Please consider that I have a quaternion that represents a rotation of a three dimensional object that is to take place, in relation to some starting orientation of that object. That rotation may be composed of various rotations around various of the axes.

So a graphics display representing the object can thus far have two possible displays. The first display representing the starting orientation of the object. The second display repesenting the finishing orientation of the object, after the rotation has taken place.

Suppose, however, that we would like to generate a sequence of displays such that each of the displays represents a successive snapshot along the smooth pathway of the transition from the starting orientation of the object to the finishing orientation of the object.

Suppose that we seek a total of six displays, that is, the starting display and a sequence of five displays each representing the view after one, two, three, four, five incremental rotations.

Previously in relation to computing rotations using quaternions the following was stated in much the following manner.

The technique for computing rotations is to have the following.

• A quaternion representing the rotation operation about a given axis.
• A quaternion representing the point in three dimensional space that it is desired to rotate about that axis.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
Once one has the three quaternions coded in the correct format, one simply loads the first of the above, multiplies it by the second of the above and then multiplies that result by the third of the above. The result is a quaternion representing the new location of the point. One simply carries out that sequence of multiplications for each point in a set of points.

The next stage is to produce a version of the above to show the rotation by the same quaternion applied twice in succession.

Please consider the following.

The technique for computing two sequential identical rotations is to have the following.

• A quaternion representing the rotation operation about a given axis.
• The same quaternion representing the rotation operation about a given axis.
• A quaternion representing the point in three dimensional space that it is desired to rotate about that axis.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
Once one has the three quaternions coded in the correct format, one simply loads the first of the above, multiplies it by the second of the above, then multiplies that result by the third of the above, then multiplies that result by the fourth of the above, then multiplies that result by the fifth of the above. The result is a quaternion representing the new location of the point. One simply carries out that sequence of multiplications for each point in a set of points.

Now please consider the following for five sequential identical rotations.

The technique for computing five sequential identical rotations is to have the following.

• A quaternion representing the rotation operation about a given axis.
• The same quaternion representing the rotation operation about a given axis.
• The same quaternion representing the rotation operation about a given axis.
• The same quaternion representing the rotation operation about a given axis.
• The same quaternion representing the rotation operation about a given axis.
• A quaternion representing the point in three dimensional space that it is desired to rotate about that axis.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
• The quaternion conjugate of the quaternion that represents the said rotation operation.
Once one has the three quaternions coded in the correct format, one simply loads the first of the above, multiplies it by the second of the above, then multiplies that result by the third of the above, then multiplies that result by the fourth of the above, then multiplies that result by the fifth of the above and so until until one multiplies the then result by the eleventh of the above. The result is a quaternion representing the new location of the point. One simply carries out that sequence of multiplications for each point in a set of points.

Suppose however that one only has the final total rotation as a quaternion. How would one find the quaternion representing the incremental rotation needed to compute each display of five steps that taken one after the other produce the total rotation?

The answer is to take the logarithm of the quaternion that represents the total rotation, divide it by 5, and then compute the exponential of the quaternion that is the result of the said division.

In 1456 object code this is simply as follows.

• Place the quaternion that represents the total rotation in aq1456.
• un5Q/ue
• The quaternion that represents the incremental rotation is in aq1456.

That is, the un command produces the logarithm of the quaternion that is in aq1456, 5Q/ divides the content of aq1456 by 5, and the ue command exponentiates the quaternion that is in aq1456.

This is all quite straightforward. If one wishes to split a rotation up into twenty steps one would use the following.

• Place the quaternion that represents the total rotation in aq1456.
• un20Q/ue
• The quaternion that represents the incremental rotation is in aq1456.

Here is a demonstration that uses the logarithm of a quaternion and the exponential of a quaternion to compute the twentieth root of a quaternion.

The demonstration is run as follows. Click on one or more of the red, orange, yellow, green, blue, magenta areas and notice that the cube rotates. When a picture that can be remembered, possibly by making a hand sketch, is reached, click on the cyan area. The diagram is then reset to the starting position and after a short delay an automatic rotation is started. After 20 steps, the result should be the same as the remembered picture.

Analysis of the software in the source code of the demo23.htm file shows the method used. When the red, orange, yellow, green, blue, magenta areas are being clicked, a quaternion representing the total rotation after the latest click is computed and recorded. This is computed by starting having a quaternion that represents the total rotation so far stored in mq1456[99]. Initially mq1456[99] is set as having the value of unity, given as follows.

1 + 0i + 0j + 0k

When one of the six rotations that is possible is produced by clicking one of the red, orange, yellow, green, blue, magenta areas, suppose that the quaternion used for the rotation is called q. Then mq1456[99] is updated to have the new value of q * mq1456[99] with the multiplication taking place in that order. This order is important. It may possibly look at first glance as if it were the wrong way round.

However, please consider that two rotations take place, first q1 and then q2 on a point of the cube whose position in space is represented by a quaternion p. Let the initial value of p be p0. Let q1' mean the quaternion conjugate of q1 and q2' mean the quaternion conjugate of q2.

Before either of the rotations have taken place, mq1456[99] contains the unity quaternion.

The first rotation produces q1 * p0 * q1' as the new value for the position of the point.

So mq1456[99] should now contain the value of q1.

The second rotation produces q2 * q1 * p0 * q1' * q2' as the new value for the position of the point.

So the quaternion for the total rotation after the two rotations is given by q2 * q1.

So, how does one get q2 * q1 from mq1456[99] using q2?

Yes, compute q2 * mq1456[99] as mq1456[99] already contains the value of q1.

Let a third rotation take place, namely q3 with q3' meaning the quaternion conjugate of q3.

The new value for the position of the point is thus q3 * q2 * q1 * p0 * q1' * q2' * q3' and the new total rotation is thus computed as q3 * q2 * q1 by computing q3 * mq1456[99] where mq1456[99] at just before this compuation contains the value of q2 * q1.

When the cyan area is clicked, the twentieth root of the quaternion is computed and the automated sequence is set up and started. Please note that the automated sequence will run continuously and does not stop after twenty steps have been completed.

1456 object code provides a number of functions of a quaternion variable, where the value of aq1456 is taken and replaced with the value of the chosen function for that argument.

When I implemented the functions of a complex variable in 1456 object code I used the book Tables of Integrals and other Mathematical Data by Mr. H. B. Dwight, fourth edition, which is a book of which I have been pleased to own a copy for many years, as a source of expressions for the functions of a complex variable in terms of functions of real variables. In implementing the functions of quaternion variables I have used the web page at http://world.std.com/~sweetser/quaternions/intro/tools/tools.html by Mr. D. Sweetser entitled A quaternion algebra tool set as a source of expressions for the functions of a quaternion variable in terms of functions of real variables.

In implementing in 1456 object code those functions of a single quaternion variable that produce a quaternion as their result I have been fascinated to observe how using a quaternion of the form

a + bi + 0j + 0k

as the argument to such a function produces a result of the form

c + di + 0j + 0k

paralleling the functions of a complex variable. That is, if there is zero in the j and k parts before the function is taken, then there will be zero in the j and k parts of the result of taking the function.

I have been even more fascinated to observe, when there are non-zero values in two or three of the i, j and k parts, how the corresponding function of a complex variable is in a way unfolded to produce the function of the quaternion variable.

It is interesting to use the formulae in the quaternion algebra tool set mentioned above to produce a set of formulae for the functions of a complex variable. This can be achieved by setting the coefficients of the j and k parts of the quaternion that is the argument to the function to zero. It is interesting to observe how, when there is zero in the j and k parts of the quaternion, various parts of the functions cancel out.

 uh aq1456 takes the value of the quaternion conjugate of aq1456 ur aq1456 takes the value of the reciprocal of aq1456, that is 1/aq1456 us aq1456 takes the value of the sine of aq1456 uc aq1456 takes the value of the cosine of aq1456 ue aq1456 takes the value of the exponential of aq1456 un aq1456 takes the value of the logarithm of aq1456 uq aq1456 takes the value of the square root of aq1456 ui aq1456 takes the value of the hyperbolic sine of aq1456, that is the sinh function uo aq1456 takes the value of the hyperbolic cosine of aq1456, that is the cosh function

This is a convenient place to mention the Q. function. The Q. function takes aq1456 and bq1456 as its arguments and uses just the non-real parts to produce a scalar result, which is placed in ad1456. If aq1456 contains

p + ui + vj + wk

and bq1456 contains

q + xi + yj + zk

then ad1456 will contain the number computed from

ux + vy + wz

after the performance of the Q. function.

 Q. ad1456 takes the value of the dot product of the non-real parts of aq1456 and bq1456, treated as if they were vectors each of 3 elements.

It is natural to compare the selection of functions of a quaternion variable that are available in 1456 object code with the selection of functions of a complex variable that are available in 1456 object code. Please note that there is no ut command, which would be where aq1456 takes the value of the tangent of aq1456. This is because there is ambiguity in how this division would take place. The tangent function of a quaternion may be computed by first computing the sine of the quaternion using us and the cosine of the quaternion using uc and then computing the value of the sine divided by the value of the cosine. The division could be performed using either u/ or u| as desired.

In addition, it is also possible that other functions of a quaternion variable could be computed within a 1456 applet landscape by use of the software interrupt facility of 1456 object code. However, please note that there are no facilities provided for simulated direct memory access of quaternions. In the event of such a function of a quaternion variable being desired, then the computation would need to be carried out by taking the quaternion argument out of the quaternion dome and passing it to the 1456 applet landscape as four doubles and returning the result as four doubles and then loading them into the quaternion dome. Thus, the desired effect could be achieved.

There are no comparison instructions provided for quaternions. Comparisons are performed using the comparison commands for doubles, typically after either the real part of a quaternion, or one of the imaginary parts of a quaternion, or the modulus value of a quaternion have been produced in ad1456 using QR, QI, QJ, QK or Qr respectively.

1456 object code

Copyright 2001 William Overington