SECTION 3.11 PROGRAMMING EXAMPLES AND EXERCISES 95
Fill in the function such that it computes the cross product, according to the method
of in Section 3.7. The function
dual() is available to compute the dual of multivectors.
If you need the pseudoscalar, use the constant
I3, or its inverse, I3i.
You can check that your implementation works by running the example: drag the input
vectors (red and green) around, and verify that the blue vector stays orthogonal to them.
3.11.3 RECIPROCAL FRAMES
In this example, we explore the construction of reciprocal frames as explained in
Section 3.8. The example program allows you to manipulate three vectors and see the
reciprocal frame of these three vectors. Drag the mouse (using any button) to change
the vectors and orbit the scene. When you play around with the example, note the
following:
•
When you make a vector longer, its reciprocal vector becomes shorter.
•
The reciprocal of a vector is always orthogonal to the other two vectors in the origi-
nal frame. The easiest way to verify this is by “orbiting” the scene, but you may want
to take it upon yourself to draw the orthogonal plane as an exercise.
Figure 3.11 lists the code to compute a reciprocal frame.
Note that the example code uses a class called
mv. In the code shown so far, we always used
specialized multivector classes such as
vector, bivector, and trivector. The general
multivector class
mv is required here because we have the need for variables that can hold
different multivector types. For example, in the following loop, the multivector
P holds
four types of values: first a scalar, then a vector, then a bivector, and finally a trivector.
mvP=(i&1)? —1.0f : 1.0f; // = pow( — 1, i)
for (unsigned int j = 0; j < nbVectors; j++)
if (j != i) P ^= IF[j];
Working with general multivectors is not as efficient as working with specialized
multivectors, but sometimes we cannot avoid them.
3.11.4 COLOR SPACE CONVERSION
The reciprocal frame algorithm can be used to do color space conversion. Common
conversions (e.g., RGB to YUV) are from one orthogonal frame to another, so that the
reciprocal frame is not really necessary. The following is an example when computing
the reciprocal frame is required.
Suppose you want to detect the light emitted by red, green, and blue LEDs in a digital
image. The colors of the LEDs are unlikely to be pure red, pure green, and pure blue
in the RGB color space. But it is possible to transform the color space such that the
LEDs do register as such coordinate directions. First, measure the RGB values of the
different LEDs in the digital image. Then, compute the reciprocal frame of these three