There are significant differences between the basis and results of the standard trigonometric functions, such as implemented in other languages, and as implemented in Netlogo.

The differences are designed to make working with these functions easier and more intuitive for students and other modelers who are not familiar with traditional trigonometry.

There are also helper reporters designed to make certain difficult trig problems easier.

Differences with "traditional" Trigonometry

  • Input and output angles are always in degrees, not radians.
  • Zero degrees is at north/up/top-dead-center, NOT east/left
  • Angles increase clockwise, not widdershins
NetLogo “Standard”
Angle measures degrees radians
0 degrees North/Up East/Right
angles increase clockwise widdershins
tangent is x over y y over x

NetLogo Trig Relationships

Given a point with coordinates x and y and the heading h from the origin to that point, some useful things to know:

  • The heading is measured clockwise from north.
  • The distance from the origin to (x,y) is given by (DISTANCEXY x y)
  • x = ( sin h ) * distancexy x y ;; if abs x ⇐ 1.0, then x = sin h
  • y = ( cos h ) * distancexy x y ;; if abs y ⇐ 1.0, then y = cos h
  • atan x y = h (see note below)
  • x / y = tan h
  • towardsxy x y = h (see note)

Turtle primitives and NetLogo Trigonometry

  • HEADING is the angle toward which the turtle's “nose” is pointing.
    • it is the direction that the turtle will move as a result of JUMP or FORWARD or FD
    • it is the direection the turtle will look when it uses PATCH-AHEAD and IN-CONE
  • DX and DY reporters report the X and Y component of the unit vector with the turtle's heading.
    • In other words, they give the relative coordinates of a point that is 1 unit from the turtle's location, in the direction the turtle is facing.
    • In other words, (xcor + dx) (ycor + dy) are the new coordinates of the turtle, if it does JUMP 1.
  • dx = sin heading
  • dy = cos heading
  • atan dx dy = heading
  • dx / dy = tan heading

Notes

ATAN

Note that the NetLogo atan reporter is quadrant-aware, that is, it accepts negative inputs, and reports the correct 0 to 360 degree heading. If both x and y are zero, a run-time error occurs.

TOWARDS

With towards or towardsxy, if the target location is the same as the current location a runtime error occurs.

E.g. “ASK TURTLES [ SET HEADING TOWARDS SELF ]” will cause a runtime error (if there are any turtles)..

FACE

With FACE or FACEXY, no action or error occurs if the target location is the same as the current location.

E.g. “ASK TURTLES [ FACE SELF ]” will not cause a runtime error, and the turtles will not change heading.

 
guide/trigonometry.txt · Last modified: 2012/06/21 00:57 by james
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki