Topic 20 - 3D Turtles

WinLogo contains some primitives to assist with drawing shapes in three dimensions. Here is some introductory code:

TO SQUARE :SIDE
REPEAT 4 [FORWARD3D :SIDE ROTATEZ 90]
END

TO CUBE :SIDE
REPEAT 4 [SQUARE :SIDE FORWARD3D :SIDE ROTATEY 90]
END

CUBE 50

 

 

 

 

Now clear the screen and the 3D settings and try the following which rotates the cube through the X axis only:

CS

CLEAN3D

REPEAT 1000 [ROTATEX 5 CUBE 50 CLEAN CLEAN3D]

You can change the 'X' at the end of ROTATE to 'Y' or 'Z' to change the axis of rotation, and you can also put any two of the ROTATE primitives in combination. Finally you can try the following which rotates the cube through all three axes:

CS
CLEAN3D
REPEAT 1000 [ROTATEX 5 ROTATEZ 5 ROTATEY 5 CUBE 50 CLEAN CLEAN3D]

To try and understand what is going on here let us break down the two functions into their constituent commands:

TO NEWCUBE

FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90 
FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90
FORWARD3D 50
ROTATEY 90

FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90 
FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90
FORWARD3D 50
ROTATEY 90

FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90 
FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90
FORWARD3D 50
ROTATEY 90

FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90 
FORWARD3D 50 ROTATEZ 90 FORWARD3D 50 ROTATEZ 90
FORWARD3D 50
ROTATEY 90

END

This has drawn a single cube from four separate squares which we can now rotate as before with:

CS CLEAN3D HT
REPEAT 1000 [ROTATEX 1 ROTATEY 1 CLEAN NEWCUBE]

Watch the rotating cube carefully and try to understand what is happening. 3D geometry is much harder to understand than two dimensional and it is difficult to appreciate fully how the cube is being drawn and redrawn with each cycle. Just as you did with trees you have to try out basic operations with different parameters until you understand what effect those values have on the behaviour of the turtle.

By changing the parameters of the ROTATEX and ROTATEY commands we can make the cube rotate in various ways:

CS CLEAN3D HT
REPEAT 1000 [ROTATEX 0 ROTATEY 1 CLEAN NEWCUBE]

CS CLEAN3D HT
REPEAT 1000 [ROTATEX 1 ROTATEY 1 CLEAN NEWCUBE]

CS CLEAN3D HT LT 135
REPEAT 1000 [ROTATEX 1 ROTATEY 1 CLEAN NEWCUBE]

CS CLEAN3D HT LT 135
REPEAT 1000 [ROTATEX 1 ROTATEY -1 CLEAN NEWCUBE]

CS CLEAN3D HT LT 135
REPEAT 1000 [ROTATEX -1 ROTATEY 1 CLEAN NEWCUBE]

CS CLEAN3D HT LT 90
REPEAT 10000 [ROTATEY -1 ROTATEX -1 ROTATEZ 1 CLEAN3D CLEAN NEWCUBE]

And so on... You will notice in these variations of rotating the cube that different axes are kept stationary. I wanted to keep a diagonal axis, between opposite corners, stationary, and it took a lot of time to achieve it (the last pair of lines above).

What we see, eventually, is that if ROTATEX and ROTATEY have parameters of minus 1 and ROTATEZ has a parameter of plus 1 then the cube rotates around a diagonal axis. If ROTATEX or ROTATEY are have positive parameters then the rotation is based on a single point.

This set of parameters produces a particularly complex rotation:

CS CLEAN3D HT
REPEAT 10000 [ROTATEY 1 ROTATEX 0 ROTATEZ -1 CLEAN NEWCUBE]

Return to Logo Home Page