(STOLEN FROM TURTLE GEOMETRY)








BEHAVIOR (in 2D)

Basic Movements

Turtle Geometry vs. Coordinate Geometry

Expressing the Turtle in terms of the Coordinate system

Need to keep some global variables:

This makes turning easy:

In order to move forward 1 unit:

So:


float t;
static float dt, prevtime = 0;

t = CAVEGetTime();
if (t>prevtime && (t-prevtime)<1) dt = t - prevtime;
prevtime = t;

Modeling Smell

Find by Smell

In order to simulate SMELL the Turtle needs to receive information from the environment. We can then simulate the movement of Turtle to find food based on its ability to smell the food.

Simplest Way

Not based on level of smell, but only on whether the smell is getting stronger or weaker.
DISTANCE(X1, Z1, X2, Z2)
    DX = X2 - X1
    DZ = Z2 - Z1
    RETURN SQRT(DX^2 + DZ^2)
    

TO SMELL IF DISTANCE.TO.FOOD > DISTANCE.LAST.TIME THEN RESULT = "WEAKER" ELSE RESULT = "STRONGER" DISTANCE.LAST.TIME = DISTANCE.TO.FOOD RETURN RESULT
TO FIND.BY.SMELL2 (TURN) REPEAT FOREVER FORWARD 1 IF SMELL = "WEAKER" THEN RIGHT (TURN)


Slightly more interesting way (still very simple)

To make it a bit more realistic, add some random motion
 	
TO FIND.BY.SMELL3 (D1, D2, SMELL.TURN, RAND.TURN)
    REPEAT FOREVER
        FORWARD RAND (D1, D2)
	LEFT RAND (-RAND.TURN, RAND.TURN)
	IF SMELL = "WEAKER" THEN RIGHT SMELL.TURN

If we observe the behavior, if the RIGHT TURN Angle remains constant, as the range of random LEFT TURN Angle increases, the path degenerates.


Modeling Sight

Receiving information from the environment

In order to simulate vision, the Turtle must again get some information from the environment. A simple model that is similar to the SMELL examples above concerns itself with only the intensity of light that reaches the Turtle's eye. The major difference between these SIGHT and SMELL models is that SIGHT is directional; it is dependent upon the Turtle's direction with respect to the stimulus.

Assuming that the Turtle can sense a light source, it needs the ability to TURN to FACE it.


 
TO TOWARDS [PX PZ]
    [DX DZ] = [P2X-Xpos -(P2Z-Zpos)]
    IF DX > 0 THEN RETURN ARCTAN (DY/DX)
    IF DX < 0 THEN RETURN 180 + ARCTAN (DY/DX)
    RETURN 90 * SIGN DZ
    

TO BEARING POINT RETURN TOWARDS(POINT)-HEADING
TO FACE POINT LEFT BEARING(POINT)


Keep a Bearing

One possible model is to have the Turtle move while keeping some point (for instance, a LIGHT) at a fixed bearing.
 	
TO KEEP.A.BEARING POINT ANGLE
    REPEAT FOREVER
        FACE POINT
	LEFT ANGLE
	FORWARD 1

If we observe the behavior, we can see that it causes the Turtle to spiral around the LIGHT


Two-eye Model

The Turtle could also use vision to face a point. It has two eyes, each with its own field of vision. Depending on the angles that define these fields of view for each eye, there may be some overlap where both eyes can see.
 	
TO RIGHT.EYE.SEES POINT
    IF BEARING(POINT) > 300 THEN RETURN "TRUE"
    IF BEARING(POINT) < 10 THEN RETURN "TRUE"
    RETURN "FALSE"
    

TO LEFT.EYE.SEES POINT IF BEARING(POINT) > 350 THEN RETURN "TRUE" IF BEARING(POINT) < 60 THEN RETURN "TRUE" RETURN "FALSE"


Head for a Point


     
TO HEAD.FOR POINT
    REPEAT FOREVER
        IF EITHER
	     LEFT.EYE.SEES(POINT) ,
	     RIGHT.EYE.SEES(POINT)
	   THEN FORWARD 10
	   ELSE LEFT 10


Two-eye Model with Intensity

Increasing the amount of information received from the environment creates a more sophisticated criterion for making decisions about which direction to travel in order to reach a desired destination. We will now modify to include INTENSITY of a light source, not only whether it falls within the field of vision.

INTENSITY is dependant on:


 	   	
TO INTENSITY.LEFT SOURCE
    IF NOT LEFT.EYE.SEES(SOURCE) THEN RETURN 0
    FACTOR = STRENGTH / (DIST(SOURCE)^2)
    ANGLE = BEARING (SOURCE) - 45
    RETURN (FACTOR * COS(ANGLE))
    

TO INTENSITY.RIGHT SOURCE IF NOT RIGHT.EYE.SEES(SOURCE) THEN RETURN 0 FACTOR = STRENGTH / (DIST(SOURCE)^2) ANGLE = BEARING (SOURCE) + 45 RETURN (FACTOR * COS(ANGLE))
*note that the ANGLE computation includes an offset of 45 degrees (negative for the LEFT eye and positive for the RIGHT eye) from the Turtle's heading.


To include INTENSITY in a SIGHT model simply:


TO FIND.BY.SIGHT
    REPEAT FOREVER
    FORWARDS 1
    IF INTENSITY.LEFT(SOURCE) > INTENSITY.RIGHT(SOURCE)
        THEN LEFT 10
	ELSE RIGHT 10


Some Possible Variations



Sources for more information

Turtle Geometry
Abelson, Harold and Andrea A. diSessa
c. 1980 by The Massachusetts Institute of Technology
part of The MIT Press Series in Artificial Intelligence

Look here for more sources soon!


back to NOW

back to insley on the internet