Understand Your Orientation in 3D

In 2D life is simple:

In 3D, (PERSPECTIVE) mode things are bit more complicated:

However, there is more to it than that. ROLL can also affect your HEADING. PITCH can also affect your ROLL, and so on. They all interact with one another. The easiest way to understand this is with an example:

PERSPECTIVE
RIGHT 90
(SHOW ROUND ROLL ROUND PITCH ROUND HEADING)
0 0 90
CLEARSCREEN
DOWNPITCH 90
RIGHTROLL 90
UPPITCH 90
(SHOW ROUND ROLL ROUND PITCH ROUND HEADING)
0 0 90

The example above only uses rolls and pitches but the heading changed. But it is correct, think about the maneuvers I made and where the turtle should be pointing.

But don't worry, FMSLogo makes it easy, you just need to understand some basic rules so that you don't get lost in 3D space. The turtle controls ROLL, PITCH, and HEADING do affect one another but in a certain way which is important. The most important is that a change in HEADING (with RIGHT, LEFT or SETHEADING) does not effect your ROLL or PITCH. This is what allows you to use a lot of your existing 2D code in 3D.

There is also another rule to understand, you cannot simply say:

PERSPECTIVE
SETROLL 45
SETPITCH 45
SETHEADING 45
(SHOW ROUND ROLL ROUND PITCH ROUND HEADING)
45 45 45

And expect to be at an absolute orientation of 45, 45, 45.

CLEARSCREEN
RIGHT 45
RIGHTROLL 30
UPPITCH 30
; Now try to set your self up to 45,45,45 again
SETROLL 45
SETPITCH 45
SETHEADING 45
(SHOW ROUND ROLL ROUND PITCH ROUND HEADING)
248 29 45

But don't worry there is an easy solution, the SETORIENTATION command.

CLEARSCREEN
RIGHT 45
RIGHTROLL 30
UPPITCH 30
; Now try to set your self up to 45,45,45 again
SETORIENTATION [45 45 45]
(SHOW ROUND ROLL ROUND PITCH ROUND HEADING)
45 45 45

SETORIENTATION understands the interactions between ROLL, PITCH and HEADING. All SETORIENTATION knows is that it has to do things in the correct order. It basically backs out your current orientation and applies the requested one. It does this in a very specific order. Your current orientation can also be reported or saved using the ORIENTATION command.

CLEARSCREEN
RIGHT 45
SHOW ORIENTATION
[0 0 45]
MAKE "saveit ORIENTATION
RIGHT 90
UPPITCH 180
SETORIENTATION :saveit
SHOW ORIENTATION
[0 0 45]

There is also another command that knows about your ORIENTATION and that is TOWARDSXYZ. TOWARDSXYZ outputs an orientation that is compatible with SETORIENTATION.

SETORIENTATION TOWARDSXYZ [100 100 0]
SHOW ORIENTATION
[0 0 45]
FORWARD DISTANCEXYZ [100 100 0]
SHOW POSXYZ
[100 100 0]

Having said all that, you don't really need to think in terms of absolute ORIENTATION. ORIENTATION and SETORIENTATION are used mostly to save, report and restore your ORIENTATION (just like you do with HEADING and SETHEADING in 2D). And like explained earlier changes in your heading with RIGHT, LEFT and SETHEADING only effect what they effected in 2D (your HEADING).

You should also be thinking the same way you do in 2D. You don't often worry about your absolute HEADING in 2D, it's most often a turn relative to your current HEADING. It's no different in 3D except you have more ways to turn. Think like the turtle is an airplane and you're in the cockpit. Then decide where you want to go next.


SourceForge.net Logo