TITLE: Turtle geometry in 3D
QUESTION [5 upvotes]: I'm undertaking a small project whereby I'm trying to recreate the educational programming language Logo.
For those who don't know it, Logo consists of a 'turtle' which starts at the (x, y) location (0, 0) and can then move forwards and backwards to draw lines. In addition, the turtle can turn to the right or left infinitely (I.E. the angle 'wraps' at 360 back to zero when turning clockwise, and has the same property in the counter-clockwise direction.)
Students can then use commands like FD to move the turtle forward, or RT to turn to the right. So, for example, the program FD 10 RT 90 FD 10 RT 90 FD 10 RT 90 FD 10 RT 90 would draw a square with sides of 10-units in length.
My turtle has x, y and angle properties, and when I supply d to specify the distance to travel, I can easily calculate the new values of x and y with the following:
old_x = x
old_y = y
r = angle * (pi / 180) # convert angle (in degrees) to radians
new_x = old_x + (d * cos(r))
new_y = old_y + (d * sin(r))
I then draw a line from (old_x, old_y) to (new_x, new_y). So far, so good. I'm able to move the turtle perfectly in two dimensions.
But, what I'd like to do now, is add UT and DT commands to my program, so that it is possible to move the turtle's nose up and down, so that we can now draw 3D shapes. For example, the program FD 10 UT 90 FD 10 UT 90 FD 10 UT 90 FD 10 UT 90 would still draw a square, only now it would standing vertically.
I know my graphics library (OpenGL) supports drawing lines in 3D, infact that's what I'm already doing, only I'm keeping the z dimension zero the whole time, and obviously I'll need to keep track of a second angle variable for up and down, but I've absolutely no idea of how to go about calculating the new x, y and z values given two angles.
Can anyone help? Many TIA.

REPLY [2 votes]: In my book
Edgar, Gerald A., Measure, topology, and fractal geometry, Undergraduate Texts in Mathematics. New York etc.: Springer-Verlag. ix, 230 p. DM 58.00/hbk (1990). ZBL0727.28003.
in Chapter 7 "Additional Topics" I propose a 3D turtle geometry.  (This is in the First Edition of the book only.  In the Second Edition, I included different additional topics.)  In addition to the usual turns (yaw) and the turns you propose (pitch) there is also roll.  Here is p. 196:

At the bottom is a code for a 3-dimensional dragon...