The magazine of the Melbourne PC User Group
Dancing Stars - Part 3
Four Stars in Stereo
Ken Holmes |
 |
To see the two pairs of binary stars orbiting in stereo, we need to provide
each eye with its own true perspective of the situation. My favoured method, as many members know, is the
dreaded mirror; it is simple and effective. We use, as the arena for action, the right half of the screen and
put there the perspective as seen by the right eye. The left eye's perspective is calculated for the right
screen but is plotted on the left, mirror-flipped about the centreline. We need a mirror about 30 cm. wide
and the height of the screen (25 cm), abutting the screen vertical centreline and at right angles to the
screen, facing left. With the nose on the outer edge, the right eye sees its correct perspective on the right
whereas the left eye, ignoring the left screen, views its reflection in the mirror, which is, of course,
flipped back to its true perspective on the right.
As the half screen is in "portrait" mode, in Listing 3 we put the four stars on a vertical line initially.
Stars 1 and 2 form the first binary at the top, and stars 3 and 4 form the second binary below.
| Our system of axes will have the origin at screen bottom-centre
with +x to the right along the bottom, +y up the centre and +z into the screen. Using WINDOW puts the y axis
the right way up - y increasing upwards. We will use circular orbits for the two binaries and a small
eccentricity for their large orbit, ie. a "circularity factor" of 0.8. Firstly, we calculate the velocities
to put stars 1 and 2 in circular orbits and allocate them parallel to the z axis. Then, we do the same for 3
and 4 and allocate the velocities parallel to the x axis. Next, we do the same for the two pairs and allocate
the velocities for each pair parallel to the z axis; this means that the pairs will orbit in a vertical
plane. Stars 1 and 2 will orbit each other in the same plane as the big circuit and so trace out epicycloidal
paths; stars 3 and 4 will orbit in the vertical plane at right angles, which moves around the big circuit, so
the paths will vary from cycloidal to helical each quarter revolution. |

Figure 7. Taking a stereo perspective.
|
The Core Code
The code in Part 2 coped with three dimensions and four stars of different masses, so will again serve here.
We only have to provide the left eye with its flipped view on left screen.
Getting Stereo
In Part 2, Figure 6, we saw a side view illustrating how, using similar triangles, we can readily find the
screen intersection for our line-of-sight to any point in three dimensions and, thus, provide true
perspective. In that case, a plan view would be equally simple. In the present case, Figure 7 is a plan view
to show how we find the x screen position for each eye and also flip the left eye's point across the
centreline (x = 0) by negating its value. Note the similarity of Listing 3 to Listing 2, apart from a couple
of lines to calculate and plot the left eye points. The printed result in Figure 8 is smaller than on screen
and has a white background, but you may still see the stereo effect using a mirror. On screen, the bright
pixels on a black background are much more effective than light reflected from the page - and it's
bigger.
|

Figure 8. Full circuit of four stars.
|
Next Month
We will attempt a stereo of three pairs of binaries moving in the stable figure of eight we saw in Part 1;
the code readily extends to six stars. Serious experimenters with single purpose computers are dealing with
many thousands of stars in global clusters. Recently, they are including notional planets to see how planets
might be stripped from the parent star by passing stars, to wander free in interstellar or, even,
intergalactic space. There is evidence, from gravitational lensing of light from more distant sources by
intermediate bodies which may be brown dwarf or planet sized.
'Listing 3 dstars3.bas
DEFINT I-K
DIM m(4), x(4), y(4), z(4) 'masses & positions 4 stars
DIM vx(4), vy(4), vz(4) '...and their velocity components
DIM dsq(4, 4), a(4, 4) 'distance sqrd & accel. - i to j
DIM ax(4, 4), ay(4, 4), az(4, 4) 'x, y, z comps of accel.
DIM atx(4), aty(4), atz(4) 'x, y, z comps of total accel.
SCREEN 12: WINDOW (-320, 0)-(319, 479)'origin bottom centre
LINE (-320, 0)-(319, 479), 15, B 'border
LINE (0, 0)-(0, 479) 'mirror on centreline
LOCATE 10, 39: PRINT "M": LOCATE 12, 39: PRINT "I"
LOCATE 14, 39: PRINT "R": LOCATE 16, 39: PRINT "R"
LOCATE 18, 39: PRINT "O": LOCATE 20, 39: PRINT "R"
eyexr = 80: eyexl = -80: eyey = 480: eyez = -600 'eye posn
m(1) = 1: m(2) = 2: m(3) = 4: m(4) = 2 'easily changed
M12 = m(1) + m(2): M34 = m(3) + m(4) 'masses of binaries
f12 = 1: f34 = 1: f14 = .8 ' "circularity" factors
y(1) = 455: y(2) = 400: y(3) = 125: y(4) = 60 'y positions
x(1) = 160: x(2) = 160: x(3) = 160: x(4) = 160 'x positions
z(1) = 0: z(2) = 0: z(3) = 0: z(4) = 0 'z positions
FOR i = 1 TO 4 'mark initial positions
CIRCLE (x(i), y(i)), 6, i: PAINT (x(i), y(i)), i, i
COLOR i: LOCATE (496 - y(i)) / 16, 68: PRINT CHR$(48 + i)
NEXT
'Now get "internal" velocities of binary of 1 & 2
c12 = (m(1) * y(1) + m(2) * y(2)) / M12 'cg of 1 & 2
V1 = f12 * SQR(m(2) * (y(1) - c12) / (y(1) - y(2)) ^ 2)
V2 = V1 * m(1) / m(2) 'velocity inverse to mass
vx(1) = 0: vx(2) = 0 'velocities in x = 160 plane
vy(1) = 0: vy(2) = 0: vz(1) = V1: vz(2) = -V2
'Now get "internal" velocities of binary of 3 & 4
c34 = (m(3) * y(3) + m(4) * y(4)) / M34 'cg of 3 & 4
V3 = f34 * SQR(m(4) * (y(3) - c34) / (y(3) - y(4)) ^ 2)
V4 = V3 * m(3) / m(4) 'velocity inverse to mass
vx(3) = V3: vx(4) = -V4 'velocity parallel to x axis
vy(3) = 0: vy(4) = 0: vz(3) = 0: vz(4) = 0
'Now get "external" velocities of both binaries
c = (M12 * c12 + M34 * c34) / (M12 + M34) 'cg of all
V12 = f14 * SQR(M34 * (c12 - c) / (c12 - c34) ^ 2)
V34 = V12 * M12 / M34 'velocity inverse to mass
'Now add "external" velocity to each star
vz(1) = vz(1) + V12: vz(2) = vz(2) + V12
vz(3) = vz(3) - V34: vz(4) = vz(4) - V34
FOR n = 1 TO 9300 'main loop for one big circuit
FOR a = 1 TO 500: NEXT a 'increase count to slow down
FOR i = 1 TO 4: FOR j = 1 TO 4 'for each star...
IF i <> j THEN '...with every other star
xd = x(j) - x(i): yd = y(j) - y(i): zd = z(j) - z(i)
dsq(i, j) = xd * xd + yd * yd + zd * zd 'distance sqrd
d = SQR(dsq(i, j)) 'separation distance
a(i, j) = m(j) / dsq(i, j) 'gravitational accel. i to j
ax(i, j) = a(i, j) * xd / d 'x components
ay(i, j) = a(i, j) * yd / d 'y components
az(i, j) = a(i, j) * zd / d 'z components
END IF
NEXT j: NEXT i
FOR i = 1 TO 4 'for each star
atx(i) = 0: aty(i) = 0: atz(i) = 0 'zero the total accel
FOR j = 1 TO 4 'add x,y,z acc. due to all "other" stars
IF i <> j THEN
atx(i) = atx(i) + ax(i, j) 'cumulative x accel
aty(i) = aty(i) + ay(i, j) 'cumulative y accel
atz(i) = atz(i) + az(i, j) 'cumulative z accel
END IF
NEXT j
vx(i) = vx(i) + atx(i) 'change x velocity of i
x(i) = x(i) + vx(i) 'change x position of i
vy(i) = vy(i) + aty(i) 'change y velocity of i
y(i) = y(i) + vy(i) 'change y position of i
vz(i) = vz(i) + atz(i) 'change z velocity of i
z(i) = z(i) + vz(i) 'change z position of i
zf = eyez / (eyez - z(i)) 'z factor for perspective
xr = eyexr + (x(i) - eyexr) * zf 'screen x for right eye
xl = eyexl + (x(i) - eyexl) * zf 'screen x for left eye
yb = eyey + (y(i) - eyey) * zf 'screen y for both eyes
IF xr > 0 THEN PSET (xr, yb), i 'mark right eye position
IF xl > 0 THEN PSET (-xl, yb), i 'mark left - mirrored
NEXT i
NEXT n 'repeat the loop
DO: LOOP WHILE INKEY$ = "" 'There it is!
Click to download DSTARS3.ZIP for source listing
and executable version of this program. |
Note: This series consists of Parts 1 to 6 in PC
Update issues from December 2001 to June 2002. Click to download DSTARS.ZIP file (225 KB) which contains all text,
source and executable copies of programs used in this series.
Reprinted from the March 2002 issue of PC Update,
the magazine of Melbourne PC User Group, Australia
|