Chapter 9 – Further Programs (Ellipses)

Ellipses

For astronomical presentations an ‘ellipse’ command is sadly missed from the Spectrum (and most other micros for that matter) but the following short routines will suffice, using the machine’s trigonometry functions of SIN and COS. These routines prove much less cumbersome than some published examples using complex algebraic formulae. Also keeping the routine brief ensures that the results are executed quickly, so speeding up the PLOTting process.

Effectively an ellipse is a circle seen at an angle so that its form is compressed. With minor changes, each routine can be made to PLOT in a clockwise or anticlockwise direction with the long or major axis either vertical or horizontal.

The Ellipse routines
Key in and RUN the first routine called Ellipse (see Figure 9.6). You will notice that in most cases the variable names are sufficiently long to describe their function in the program:

xaxis = x (horizontal) coordinate position
yaxis = y (vertical) coordinate position
tilt = INPUT angle of tilt to a circle
angle = compression factor to produce an ellipse

The formula in the variable ‘angle’ contains a small make-weight value of 0.1 added to a variable ’tilt’. This is done to stop the program crashing if an INPUT of 0° is made (a circle shown edge-on). The value returned by 0° would be a truly infinite number exceeding the Spectrum’s numeric capacity which is limited to a range from 3*10-39 to 7*1038.

The short routine called Ellipse Angle Values (Figure 9.7) shows what values are returned by the formula called angle between 0° and 90° in whole degree steps.

In reality, 0° is made to return a value as if 0.10, ie 1/10° or 6′ arc, and 0.1 is added throughout the sequence. The Spectrum’s PLOTting accuracy is well below this small angle and the results (as PLOTted) are indistinguishable from whole degrees.

It should now be evident that if the somewhat improbable INPUT angle for tilt of -0.1° is made, the Ellipse program will crash because:

– 0.1 + 0.1 = 0°

Figure 9.6
An ellipse from full circle to edge-on is produced via this routine.

10 PRINT “Ellipse @ tilt=”;
30 LET xaxis=132: LET yaxis=91
50 INPUT “0CHR\$130 to 90CHR\$130 “,tilt
60 PRINT tilt;”CHR\$130 ”
70 PRINT AT 10,16;”+”
80 LET angle=1/SIN ((.1+tilt)/180*PI)
90 INPUT “step (1 to 10)”,s
100 FOR f=0 TO PI*2 STEP 1/s/10
120 NEXT f

Figure 9.7
1 REM Ellipse angle values
5 FOR x=0 TO 90
7 LET tilt=x
10 LET angle=1/SIN ((.1+tilt)/180*PI)
20 PRINT angle,tilt;CHR\$ 130
30 NEXT x

Ellipse 4
This routine is precisely the same as the above routine but is used to demonstrate the simultaneous PLOTting of four ellipses. Againthe tu.o all four ellipses and the PLOTting frequency via variables can be selected by he two INPUT commands. Figure 9.8 shows two example COPYs from the screen.

Figure 9.8
Samples of ellipses PLOTted in different directions and long (major) axes.

The ellipses are made to PLOT in a clockwise or anticlockwise direction by the exchange of the SIN and COS expressions in each half of the PLOT routine. If the routine commences with the SIN function, PLOTting starts at the 12 o’clock position: if it commences with COS, PLOTting starts at the 3 o’clock position. If the variable angle is in the first half of the PLOT routine, ellipse major axis is vertical and, if it is in the second half, the major axis is horizontal.

Line 100 contains the FOR/NEXT f loop used for PLOTting the ellipse in the form:

FOR f = 0 TO PI*2 STEP l/s*3

where 0 to PI*2 produces a full ellipse. If the expression were to read:

FOR f = PI TO PI*3 STEP…

then a full ellipse would still be PLOTted, but commencing at 180°, or, on the opposite side, at the 6 o’clock or 9 o’clock locations respectively.

Try changing the values in the FOR/NEXT f loop to test this.

10 PRINT “Ellipse 4 @ tilt=”;
30 LET x=132: LET y=76
31 LET x1=x*.6: LET y1=y*1.5
32 LET x2=x*1.2: LET y2=y*1.5
33 LET x3=x*.6: LET y3=y*.5
34 LET x4=x*1.2: LET y4=y*.5
40 LET r=35
50 INPUT “0CHR\$130 to 90CHR\$130 “,tilt
60 PRINT tilt;”CHR\$130 “: PAPER 5
70 PRINT “clockwise”,”anticlockwise”
75 PRINT “axis 1″,”2″
77 PRINT AT 12,0;”^axis 3″,”4”
79 PAPER 7
80 LET angle=1/SIN ((.1+tilt)/180*PI)
90 INPUT “step (1 to 10)”,s
100 FOR f=0 TO PI*2 STEP 1/s/3
111 PLOT x1+SIN f*r,y1+COS f*r/angle
112 PLOT x2+COS f*r,y2+SIN f*r/angle
113 PLOT x3+SIN f*r/angle,y3+COS f*r
114 PLOT x4+COS f*r/angle,y4+SIN f*r
120 NEXT f

Solid Ellipse
This routine uses the DRAW command to produce solid (filled in) ellipses. It actually executes the results about four times quicker than the previous ellipse routines, where the STEP intervals are sufficiently frequent to produce a continuous unbroken outline. This is because it is only necessary to compute one quadrant of an ellipse and to mirror the results in the remaining three quadrants sequentially. Different variable names have been assigned to this routine but the principles are precisely as before. You will notice that, as it is only necessary to compute one quadrant, the FOR/NEXT loop reads:

FOR f = 0 TO PI/2 STEP .012

only one quarter the length of… 0 TO PI*2 … used previously. The STEP interval is fixed at 0.012 as this was found, with this routine, to give the solid form required. If the ellipse is not to fill the Spectrum screen then a larger value can be tested.

The variables a and b are the x and y coordinate positions for the ellipse, where variable e provides the necessary compression to the vertical or minor axis. Line 130 PLOTs the left hand upper outline of the ellipse and Line 140 does the same for the right hand side. The DRAW routines that follow the PLOT commands in the form:

DRAW 0, – b*2

DRAW a vertical line equal to twice the value of b in a downwards direction, so completing the lower portion of the ellipse. Line 200 completes the routine by marking the major (horizontal) and minor (vertical) axes of the ellipse using the OVER command.

The ellipses are made to PLOT in a clockwise or anticlockwise direction by the exchange of the SIN and COS expressions in each half of the PLOT routine. If the routine commences with the SIN function, PLOTting starts at the 12 o’clock position: if it commences with COS, PLOTting starts at the 3 o’clock position. If the variable angle is in the first half of the PLOT routine, ellipse major axis is vertical and, if it is in the second half, the major axis is horizontal.

Line 100 contains the FOR/NEXT f loop used for PLOTting the ellipse in the form:

FOR f = 0 TO PI*2 STEP l/s*3

where 0 to PI*2 produces a full ellipse. If the expression were to read:

FOR f = PI TO PI*3 STEP…

then a full ellipse would still be PLOTted, but commencing at 180°, or, on the opposite side, at the 6 o’clock or 9 o’clock locations respectively. Try changing the values in the FOR/NEXT f loop to test this.

10 PRINT “Solid Ellipse”
20 INPUT “tilt “;z: PRINT “tilt=”;z;”CHR\$130 ”
30 LET e=SIN ((.1+z)/180*PI)
40 LET x=255/2: LET y=175/2
100 FOR f=0 TO PI/2 STEP .012
110 LET a=INT (SIN f*y)
120 LET b=INT (COS f*y*e)
130 PLOT x-a,y+b: DRAW 0,-b*2
140 PLOT x+a,y+b: DRAW 0,-b*2
150 NEXT f
200 OVER 1: PLOT 0,y: DRAW 255,0: PLOT x,0: DRAW 0,175: OVER 0

Inclined Ellipse
There are times when an ellipse is required with the major axis, neither vertical nor horizontal but in an intermediate position. This final routine ‘indicates a method of achieving this aim to a modest extent.
Figure 9.9 shows a screen COPY from the program and typical INPUTs and ellipses as PLOTted. The INPUT values for tilt and inclination (rotation of the image) may be from -90° to 90° in each case. Line 90 does the actual work of computing both these factors in the final part of the expression:

…/t + a/z

where variables t (for tilt) and z (for rotation) are the reciprocal SIN values as INPUT. The PLOTting interval (STEP 0.05) and maximum horizontal displacement (value 60 in Lines 80 and 90) are fixed but can be amended to suit the requirements.

The Ellipse routine is used frequently, sometimes in a modified form, for various programs in this book, including Saturn’s Rings, Galaxy, Binary-star Orbits. The expression ‘ellipse’ is in common use to describe the shape of planetary and particular cometary orbits and the shape of optical (lens and mirror) surfaces. Ellipse is one of a family of forms in the conic section which includes the circle, parabola and hyperbola.

Figure 9.9
Typical effects of inclination (rotation of major axis) of an ellipse via this routine.

10 PRINT “Inclined ellipse”
20 INPUT “tilt “;t,”incline “;z
30 PRINT “tilt “;t;”CHR\$130 ”
40 PRINT “incl “;z;”CHR\$130 “”
50 LET z=1/SIN ((.1+z)/180*PI)
60 LET t=1/SIN ((.1+t)/180*PI)
70 FOR n=0 TO PI*2 STEP .05
75 PLOT OVER 1;140,80
80 LET a=SIN n*60
90 LET b=COS n*60/t+a/z
100 PLOT INT (140+a),INT (80+b)
110 NEXT n: GO TO 20

Ellipses and Kepler’s Orbits
One cautionary note should be observed in using the Ellipse routines to simulate a planet in true elliptical orbit about the Sun, perhaps — where the Sun cannot be in the centre of the ellipse but at one of the foci. Here Kepler’s 2nd Law of Planetary Motion applies and the planet will ‘speed-up’ as it approaches the Sun and ‘slow-down’ as it recedes. The Ellipse program will not in this case give a perfect account of itself but on many occasions the effect can be reasonably convincing. For a correct simulation of Kepler’s 2nd Law, see the Kepler’s Orbits program in Chapter 5, and the sample screen COPYs.

Chapter 2 – Spheres Within Spheres (Celestial Sphere – X-eyed 3D)

Celestial Sphere – X-eyed 3D

This second program for producing a 3D image – again of the celestial sphere – uses an entirely different technique. A colour TV plays no specific part in it but the ZX printer does. If a ZX printer is not available, then simply use the printed screen COPY in Figure 2.2 to experiment with.

Figure 2.2 3D Celestial Spheres
Hold the book at reading distance or a little further away and cross your eyes while viewing. The two seperate images should fuse into one, giving a three dimensional picture with depth.

The system involves preparing two separate DRAWings, from two separate viewpoints, of an object appearing to possess depth. When these drawings are placed side by side and viewed by crossing the eyes (hence X-eyed) the two images can be fused into one, producing a striking 3D illusion. It is estimated that about one third of the population can do this trick without undue eyestrain and I hope that around the same percentage of Spectrum users will be able to do it!

As this is the only 3D system not requiring any viewing aid, its inclusion in this book seems justified. The system has the merit (over the TV/colour filter system just discussed) that the viewing material can be of considerable complexity — the problem of overlapping INK images does not arise.

The two COPYs produced via the ZX printer and this program should be laid out with some care (use Figure 2.2 for guidance). The notation in the bottom left corner of each COPY shows the relative position of each drawing. The centres of the two CIRCLES should be between 70mm and 100mm apart — the precise dimension is not critical. What is vital is that the N/S lines running horizontally through each drawing should be parallel. Use a rule to check that this is so before the COPY is firmly fixed to heavy duty white paper with spray mountant.

Viewing the image
The mounted COPYs for viewing should be placed at normal reading distance (or a little further away in a good light) without any shadows on them The COPYs should be looked at squarely — neither tilted nor rotated. Cross your eyes, perhaps using a finger briefly midway between eye and paper and the two images should fuse into one. The system does require that the eyes converge on a midway point but are focused on the drawings. Results are easier to obtain if you don’t over-concentrate. Keep viewing periods brief.

The program
The program is a modification of the 3D Celestial Sphere program. Even if a ZX printer is not available it is well worth keying in – even on the screen, the drawings have a 3D quality as they are PLOTted. If you intend to modify the previous program to produce this version then first delete Lines 20 and 30 and add as a direct command:

BORDER 7: PAPER 7; INK 9: CLS: LIST ENTER

This will clear the distracting magenta PAPER colour which was essential for the previous background colour.

A new Line 20 is entered, containing the DATA for a little figurine POKEd in UDG CHR\$ 154. This is FLASHed in the centre of the screen (instead of a letter O) and represents our observer in the middle of the Celestial Sphere. Two ellipses are PLOTted in this program — to represent the horizon and the celestial equator. The latter comes in two versions according to the INPUT in Line 275, ie a righthand (RH) or lefthand (LH) image, and is inclined at 45° to the horizontal. The variables t (tilt) and zx (semi-major axis) control the shape of the ellipse and variable z is fixed for the inclination. Line 500 allows for a COPY to be made or a reRUN of the program for the second COPY via a one-touch INKEY\$ command.

9 REM ***********************
10 REM 3D Celestial Sphere – X
11 REM ***********************
20 DATA 24,8,62,93,157,20,20,54: FOR f=0 TO 7: READ a: POKE USR CHR\$ 154+f,a: NEXT f
30 PRINT “3D Celestial Sphere – X image”
35 PRINT AT 1,15;”Zn”;AT 21,15;”Nd”;AT 11,5;”N”;AT 11,26;”S”;AT 11,16; FLASH 1; OVER 1;CHR\$ 154
40 PRINT AT 4,6;”Ncp”;AT 3,22;”Mer”;AT 19,23;”Scp”
45 PRINT #0; FLASH 1;”Plot horizon”
50 REM ***********************
70 LET a1=128: LET b=80: LET c=79
80 CIRCLE a1,b,c
90 PLOT a1-c,b: DRAW c*2,0
100 PLOT a1,b: DRAW -60,60: DRAW 120,-120
110 FOR f=0 TO PI*2 STEP .02
120 LET x=SIN f*c: LET y=COS f*c/3: PLOT a1+x,b+y
125 NEXT f
259 REM ***********************
260 REM input RH or LH image
261 REM ***********************
275 INPUT “RH or LH image (r/l)? “; LINE c\$
276 PRINT AT 21,0;(“RH” AND c\$=”r”)+(“LH” AND c\$”r”)+” image”
280 IF c\$”r” THEN PLOT a1,b: DRAW 10,28: DRAW -20,-56: PRINT AT 7,17;”E”;AT 16,14;”W”
285 IF c\$=”r” THEN PLOT a1,b: DRAW -5,28: DRAW 10,-56: PRINT AT 7,15;”E”;AT 16,16;”W”
300 PRINT #0; FLASH 1;”Plot star on celestial equator”
400 LET t=18: LET z=50: LET zx=61
410 IF c\$=”r” THEN LET t=30: LET zx=60
420 LET z=1/SIN ((.1+z)/180*PI)
421 LET t=1/SIN ((.1+t)/180*PI)
430 FOR n=0 TO PI*2 STEP .02
440 LET aa=SIN n*zx
450 LET bb=COS n*zx/t+aa/z
460 PLOT INT (a1+aa),INT (b+bb)
470 NEXT n: INPUT “”
499 REM ***********************
500 PRINT #0;”Press c to COPY, n for New image”: PAUSE 0
510 IF INKEY\$=”c” THEN COPY : INPUT “”: GO TO 500
520 RUN
9900 REM ***********************
9990 SAVE “3Dsphxx”

The celestial sphere explained

Letter O (our figurine in the previous program) represents an observer in the middle of a sphere. This observer stands on a horizontal plane at the intersection of the N/S and E/W lines. The point above his head is called the zenith (Zn) and below his feet the nadir (Nd). Through him passes a second but vertical plane, called the meridian (Mer), marked N, Zn, S, Nd etc.

The observer can define any point on the sphere in terms of ‘azimuth’ (horizontal) bearing from the north point of the horizon E=90°, S=180°, W=270°, and so on for any intermediate position. The vertical bearing is measured in ‘altitude’ from 0° (horizon) to 90° (zenith). He can also use negative values, eg the nadir’s altitude is -90°. The zenith and nadir are effectively the poles of the horizon coordinate system. All these reference points stay fixed – our observer is quite simply on home ground.

The observer’s sphere of horizon coordinates is shared by a second sphere called the star or celestial sphere. This second sphere is usually inclined to the first (unless our observer resides at the north pole of the Earth!) and has a virtually identical system of measuring angles, but these are called by different names. Our observer resides at a latitude of 45° north so the axis of the celestial sphere (which remains parallel to the Earth’s axis passes through him at this angle marked by the line Np (Ncp in the X-eyed program) and SP (or Scp). The star Polaris marks the north celestial pole in the sky.

Inclined at 90° polar axis is the equatorial plane which cuts through the observer’s E/W lines. In the 3D Celestial Sphere X program, this line is drawn as if by a star rising in the east, reaching its greatest altitude as it crosses the southern meridian and then setting in the west. The Star’s progress continues even when below the observer’s horizon, and 23 hours and 56 minutes later it returns to its starting point. (On the Spectrum this is speeded up to about a minute or so!). This period is used to calculate sidereal (star) time which is 4 minutes adrift from the Earth-based time of 24 hours, so the two return to sychronisation. In this way a different starry sky is presented as the seasons go by.

The star sphere is divided horizontally by a line parallel to the equator called Declination (Dec). It is measured in degrees from 0° (celestial equator) to 90° (celestial pole): south of the celestial equator, the values are negative. The lines running at 90° to the Declination lines are called Right Ascension (RA) and are similar to lines of longitude on Earth but are measured in hours instead of degrees. Each hour of RA equals 15° so that 24 hours equal 360° – a complete circle of the star sphere. Lines of RA are measured from right to left across the sky.

The RA of a star when it crosses the meridian also marks the sidereal time at that moment. This is a point worth remembering. It is only necessary to calculate the sidereal time for the day and hour (using the sidereal time program) to find which stars are due south – use a star atlas for guidance. As the stars (and the Sun, Moon and planets) are at their greatest altitude when on the meridian, they can be seen to best advantage then, particularly through a telescope.

Chapter 2 – Spheres Within Spheres (The Celestial Sphere and Coordinate Positions)

The celestial sphere and coordinate positions

Just as your Spectrum uses a two-dimensional coordinate system to PRINT and PLOT on the screen, so astronomers use a virtually identical system to represent the skies above our heads. But, whereas the Spectrum TV display is effectively small and flat, the skies have a complete ‘wraparound’ through 360°, both horizontally and vertically. One hemisphere is above our heads and one below our feet making a complete sphere.

The computation of positions on this sphere is relatively complex and requires almost constant use of trigonometry. It is beyond the scope of this book to explain the mathematics involved: in fact, this is deliberately excluded, so that you can simply key in the programs and get results without any knowledge of mathematics or trigonometry.

There are a number of coordinate systems which are used by astronomers. One we can all relate to concerns the relationship between our local horizon and the stars as they pass across the sky. This involves the conversion of, say, a star position from one system to another. A couple of experimental programs follow (experimental in their means of presentation) to explain this relationship. If you would prefer a written explanation first, go to the section headed ‘The celestial sphere explained‘ and return to the programs afterwards.