Direction vector of a turtle's heading

headdir

Returns the direction vector (cosines of angles w.r.t. the positive X and Y axes) of the current heading of a turtle.

Example:

repeat 12 [
  "v := headdir
  (print heading :v sqrt :v,1^2 + :v,2^2)
  rt 30
]

Output:
The heading, direction vector and its length is written on each repeat iteration of the example code.

0 {0 1} 1
30 {0.5 0.866025403784439} 1
60 {0.866025403784439 0.5} 1
90 {1 6.12303176911189E-17} 1
120 {0.866025403784439 -0.5} 1
150 {0.5 -0.866025403784439} 1
180 {-1.22460635382238E-16 -1} 1
-150 {-0.5 -0.866025403784439} 1
-120 {-0.866025403784439 -0.5} 1
-90 {-1 6.12303176911189E-17} 1
-60 {-0.866025403784439 0.5} 1
-30 {-0.5 0.866025403784439} 1

See also:

Table of Content