I made a stereoscopic model in October last year, however, choosing the wrong colors (red and blue on a black background, the effect was very weak (if any). This series was suggested to me last week by one of the guests here on the website, Don L. (thanks Don!), who sent me his stereoscopic cube. I opened the model, put on my goggles and his cube literally popped out of the screen.
I realized that white (which I always avoided) is a a good background, which combined with a red object and another a light blue offset object all make a nice setup for stereoscopic imaging. The red can be almost anything (orange, yellow and even green).
Now I quote from Wikipedia: “Stereoscopy (also called stereoscopic or 3-D imaging) refers to a technique for creating or enhancing the illusion of depth in an image by presenting two offset images separately to the left and right eye of the viewer. Both of these 2-D offset images are then combined in the brain to give the perception of 3-D depth.
Three strategies have been used to accomplish this: have the viewer wear eyeglasses to combine separate images from two offset sources, have the viewer wear eyeglasses to filter offset images from a single source separated to each eye, or have the light source split the images into the viewer’s eyes (no glasses required).”
Excel anaglyph stereoscopy #1 – an improved perspective rotation
– This is the first section of a tutorial on creating Excel stereoscopic models.
– Up until now we performed all the rotations separately, each rotation taking up three separate
columns. This tutorial builds a simple model where all rotations are performed in a single step.
– We know that any rotation is a linear operation and can be expressed as a matrix product
between a square “rotation” matrix and a column matrix (or vector) the “coordinate” matrix.
– The matrix product is an associative operation, therefore we can perform all three rotations in
one operation but this time the rotation matrix is the product of three matrices: the azimuth
rotation matrix, the altitude rotation matrix and the roll rotation matrix.
Excel model implementation – the input parameters:
by George Lungu
– Open a new workbook and create a parameter area like the one
in the snapshot to the right.
– Column A contains labels only. Plug in the number you see there.
– There are a total of three buttons: the upper button is called
“Yaw”, the middle button is called “Pitch” and the lower button is
– All the buttons have a range of [-1, 72] (Min=-1 and Max=72).
– The angles are expressed in degrees.
– Name the following cells: B2: “Yaw”, B4: “Pitch”, B6: “Roll”,
B8: “Eye_Screen”, B10: “Screen_Origin”
The button macros:
Private Sub Yaw_Change()
If Yaw > 71 Then Yaw = 0
– These three macros are practically identical. If Yaw < 0 Then Yaw = 71
Range(“B2”) = 5 * Yaw.Value
– When assigned to a spin button this type of macro has a roll
over property, namely while increasing the value in a cell in 5-
Private Sub Pitch_Change()
degrees increments, when reaching 355 the macro will roll
If Pitch > 71 Then Pitch = 0
If Pitch < 0 Then Pitch = 71
over to 0 rather than climb to 360.
[B4] = 5 * Pitch.Value
– Similarly when the value in the target cell reaches 0 (while
decrementing the macro variable) the macro will roll over to and continue to go down from there rather that changing If Roll > 71 Then Roll = 0
Private Sub Roll_Change()
If Roll < 0 Then Roll = 71
the target cell value to negative numbers.
[B6] = 5 * Roll.Value
Creating a cube:
C 1 1 -1 0.8
– We will create a cube using a constant D 1 -1 -1
A -1 -1 -1 F 0.5
data table: G
E -1 -1 1
– Empty rows in the table translate in curve
F -1 1 1 0.2
discontinuity. G 1 1 1
-1 -0.7 -0.4 -0.1 0.2 0.5 0.8
H 1 -1 1 -0.1
– This is not a displayable curve yet until we
E -1 -1 1
perform the 3D-2D perspective conversion. C
B -1 1 -1
– You are not supposed to chart the data F -1 1 1
yet. The chart to the left will be crated later
C 1 1 -1
G 1 1 1
in the presentation.
D 1 -1 -1
H 1 -1 1
A generic rotation matrix:
– Always we rotate around a certain axis. While the coordinate corresponding to the rotation
axis remains unchanged, the other two coordinates for any point belonging to the body change.
This makes a rotation a 2D transformation provided we choose the Cartesian coordinate system
– The following formulas were derived on this blog before. If we rotate a point around the z axis
for instance (yaw rotation) we have valid the following formulas.
final roll pitch yaw initial
first multiplication, the result
is a new coordinate vector
second multiplication, the result
is another coordinate vector
last multiplication, the result is
the final coordinate vector
The matrix multiplication is not commutative but it is associative therefore we can rewrite
the above relationship as:
Where the composite rotation matrix is:
composite roll pitch yaw
Worksheet implementation of the three rotation matrices and the composite matrix:The Yaw matrix:
– Cells E4, F4, G2, G3 are all zero, G4: “=1”
– E2: “=COS(Yaw*PI()/180)”, F2: “=-SIN(Yaw*PI()/180)”
– E3: “=SIN(Yaw*PI()/180)”, F3: “=COS(Yaw*PI()/180)”
The Pitch matrix:
– Cells J2, K2, I3, I4 are all zero, I2: “=1”
– J3: “=COS(Pitch*PI()/180)”, K3: “=-SIN(Pitch*PI()/180)”
– J4: “=SIN(Pitch*PI()/180)”, K4: “=COS(Pitch*PI()/180)”
The Composite matrix:
The Roll matrix:
– I7: “=MMULT(E7:G9,MMULT(I2:K4,E2:G4))”
– Cells E4, F4, G2, G3 are all zero, G4: “=1”
after typing that in cell I7 and hitting return,
– E7: “=COS(Roll*PI()/180)”, G7: “=-SIN(Roll*PI()/180)”
select range I7:K9 and holding F2 down press
– E9: “=SIN(Roll*PI()/180)”, G9: “=COS(Roll*PI()/180)” Ctrl+Shift+Enter.
Create a table with the data for the composite rotation of the cube:
– D16: “=TRANSPOSE(MMULT($I$7:$K$9,TRANSPOSE(A16:C16)))”
after typing that in cell D16 and hitting return, select range
D16:F16 and holding down F2 press Ctrl+Shift+Enter.
– Copy range D16:F16 down to row 34 then delete the
following ranges: D26:F26, D29:F29, D32:F32.
Create the 3D-2D perspective conversion formulas:
– The formulas for the 3D-2D perspective conversion were derived on
this blog before. They are shown on the upper right side of this page.
– ES is the distance between eye and screen and SO is the distance
between the screen and the origin of the object system of coordinates
– G16: “=Eye_Screen*D16/(Eye_Screen+Screen_Origin+E16)”
– H16: “=Eye_Screen*F16/(Eye_Screen+Screen_Origin+E16)” then copy G16:H16 down to G34:H34.
After this delete the following ranges: G26:H26, G29:H29, G32:H32
Charting the cube :
– Chart range G16:H34 onto a square 2D scatter
chart having both axes scaled between -1 and +1.
– You are ready to use the model by adjusting the
angles of rotation and watching the charted cube.
– As opposed to previous models of this type this one
has the advantage of simplicity and space saving since
only 3 columns were used for rotation instead of 9.
– You don’t have to use the Excel matrix formulas, you
can do the matrix multiplication by hand following the
same guidelines and you are still at a great advantage.
– The model is computational efficient too, since a lot
of the rotation mathematics is performed in small
area (the matrices). For large objects with many
vertices this is the way to go.
to be continued…