Boyds – Mathematical Background

(author: Reinhold Kloos)

Cartesian coordinate system with positive direction of the angle used in Polynesian coordinate system

 

Given:

Position of Boyd – x, y                                                Direction of Boyd – a

 

In the fly routine you simulate the reaction of node/agent/boyd i to its current environment.

The given values of the environment, seen relative to the position of the current boyd i are:

 

Distance nearest border  – borderD                            Direction to nearest border – borderA

Distance to nearest boyd – minD                                 Direction to nearest boyd – minA

Distance to furthest boyd – maxD                                Direction to furthest boyd - maxA

 

Turn towards an object (furthest boyd):       Just turn b around!

 

 


Why is my boyd going upwards with a = 1.5 Pi as direction?

 

… because programmer liked more to have their z – axis going away from them, virtually into the inside of the screen. They did not want to change the mathematic, the Cartesian coordinate system. Thus, they simply turned the system along the x – axis. This leads to the point that the origin is not any longer in the down-left corner but in the up-left one and the angle direction is the other way round (0.5 Pi down and 1.5 Pi up).

 

 

 

 

 

 

 

 

 

 

 


Nevertheless, the methods given above work!

(because the mathematical model was not changed!)

 

 

 

 

Further remarks

*  Use the procedure mod2pi, if you do arithmetic operations with angles in order to keep the resulting angle in the area from 0 to 2 pi.

*  Make the area around the boyd big enough in order to avoid obstacles

*  Make a case, dealing with nearest wall and nearest boyd together (The direction A would be average direction between borderA and minA).

*  Have always only one resulting move of an boyd in fly. The avoidance of obstacles should be most important.

 

Improvements

It may be easier to use Cartesian vectors instead of Polynesian ones (Pseudocode).

 

Sometimes it happens, that a lot of boyds are near to one boyd and it is rather difficult to avoid a collision with the other ones, if you only consider the nearest boyd.

A similar case is given, when the boyd is near a corner and two walls are near. A workaround is to extend the area around the boyd. However, this works only partly.

 

The only solution is to consider all boyds and walls in your reaction area. This is fine, if there are only two objects (like nearest wall and nearest boyd explained under further remarks). However, if there are more than two obstacles relevant, it is more complicated. Sometimes, the boyd can only wait until the coast is clear. Here a possible algorithm:

*  Find out the resulting directions {b1, b2, … }for all obstacles. If they all turn away in the same direction, do it. Otherwise the boyd has to wait.
      (For this purpose, it is necessary to introduce a new Boolean stop-field to the node, and an array with pairs of (A, D) for all obstacles.)

*  If a boyd is stopped, then there is certainly no moving direction of the boyd given. A new moving direction has to be found:
Find out, if all directions to the obstacles are in a sector of maximal Pi (180 degree). If so, determine the new direction of the boyd as the
opposite direction of the average direction (simply add one Pi). Otherwise keep waiting.

 

You can prove inductively that there will be always some boyds, which can move.