de.steeringbehaviors.simulation.behaviors
Class ObstacleAvoidance

java.lang.Object
  extended by de.steeringbehaviors.simulation.behaviors.Behavior
      extended by de.steeringbehaviors.simulation.behaviors.ObstacleAvoidance
All Implemented Interfaces:
ObjectAttributes

public class ObstacleAvoidance
extends Behavior

ObstacleAvoidance Implements the ObstacleAvoidance behavior. This behavior is used to steer an object around obstacles in its way.


Field Summary
protected  double m_length
          Length of the testing cylinder
protected  Obstacle m_nearest
          Object nearest to our vehicle
protected  Neighborhood m_neighborhood
          A neighborhood object used for spatial queries
protected  java.util.Vector m_obstacles
          Array of obstacles to test for collsions
protected  java.util.Vector m_polyPoints
          Array used to store the points of a polygon for intersection - testing
protected  double m_radius
          Radius of the testing cylinder
protected  Vector2d m_result
          Resulting steering force
protected  Obstacle m_tempObstacle
          Current object to be tested
protected  Vector2d m_test
          Vector used for testing for possible collsions
protected  double m_testlength
          Current length of the testing cyclinder
protected  Vector2d m_theNormal
          Resulting normal vector
 
Fields inherited from class de.steeringbehaviors.simulation.behaviors.Behavior
m_behaviorName, m_influence, m_needsNeighborhood
 
Constructor Summary
ObstacleAvoidance()
          Constructor
ObstacleAvoidance(double radius, double vlength, double influence)
          Constructor
 
Method Summary
 Vector2d calculate(Vehicle v)
          Calculates the resulting force vector for this frame
 void init()
          Inits the object
 void setAttribute(java.lang.String name, java.lang.String value, java.util.Hashtable objectList)
          Sets a attribute specified by the name
 void setObstacles(java.util.Vector obstacles)
          Sets the array of obstacle to test for collisions each frame
 boolean setSpecialObject(java.lang.String objectDesc, java.lang.Object specialObject)
          Use this function if you need to pass a special object to certain behaviors, but do not know which behavior really recognizes this object.
protected  double xaxis_circle_intersect(Point2d o_pos, double radius, Vector2d normal)
          xaxis_circle_intersect Test a circle for intersection with the local x axis of the vehicle.
protected  double xaxis_poly_intersect(Vehicle v, Vector2d normal)
          xaxis_poly_intersect Test a polygon for intersection with the local x axis of the vehicle.
protected  double xaxis_rect_intersect(Vehicle v, Point2d o_pos, Point2d p1, Point2d p2, Point2d p3, Point2d p4, Vector2d normal)
          xaxis_rect_intersect Tests a rectangle for intersection with the local x axis.
 
Methods inherited from class de.steeringbehaviors.simulation.behaviors.Behavior
getBehaviorName, getInfluence, needsNeighborhood, setInfluence, setNeighborhood
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_result

protected Vector2d m_result
Resulting steering force


m_test

protected Vector2d m_test
Vector used for testing for possible collsions


m_radius

protected double m_radius
Radius of the testing cylinder


m_length

protected double m_length
Length of the testing cylinder


m_obstacles

protected java.util.Vector m_obstacles
Array of obstacles to test for collsions


m_polyPoints

protected java.util.Vector m_polyPoints
Array used to store the points of a polygon for intersection - testing


m_testlength

protected double m_testlength
Current length of the testing cyclinder


m_nearest

protected Obstacle m_nearest
Object nearest to our vehicle


m_neighborhood

protected Neighborhood m_neighborhood
A neighborhood object used for spatial queries


m_tempObstacle

protected Obstacle m_tempObstacle
Current object to be tested


m_theNormal

protected Vector2d m_theNormal
Resulting normal vector

Constructor Detail

ObstacleAvoidance

public ObstacleAvoidance()
Constructor


ObstacleAvoidance

public ObstacleAvoidance(double radius,
                         double vlength,
                         double influence)
Constructor

Parameters:
radius - Radius of testing cylinder
vlength - Length of the testing cylinder
influence - influence of the behaviour
Method Detail

init

public void init()
Inits the object


setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value,
                         java.util.Hashtable objectList)
Sets a attribute specified by the name

Specified by:
setAttribute in interface ObjectAttributes
Overrides:
setAttribute in class Behavior
Parameters:
name - name of the attribute
value - value of the attribute
objectList - hashtable of all steeringobjects

setObstacles

public void setObstacles(java.util.Vector obstacles)
Sets the array of obstacle to test for collisions each frame

Parameters:
obstacles - Array of obstacles

setSpecialObject

public boolean setSpecialObject(java.lang.String objectDesc,
                                java.lang.Object specialObject)
Use this function if you need to pass a special object to certain behaviors, but do not know which behavior really recognizes this object. If a behavior recognized the objectDesc, it will return true and cast the object to the correct type internally. If the behavior does not know the objectDesc, it will return false.

Overrides:
setSpecialObject in class Behavior
Parameters:
objectDesc - A string that represents a certain object type
specialObject - An instance of a special object that corresponds to the objectDesc
Returns:
True if the behvaior recognized the description, otherwise False

calculate

public Vector2d calculate(Vehicle v)
Calculates the resulting force vector for this frame

Overrides:
calculate in class Behavior
Parameters:
v - The vehicle
Returns:
Returns the resulting force

xaxis_circle_intersect

protected double xaxis_circle_intersect(Point2d o_pos,
                                        double radius,
                                        Vector2d normal)
xaxis_circle_intersect Test a circle for intersection with the local x axis of the vehicle. Returns -1 if there is no intersection else returns the x position of the intersection. The normal parameter is set to either point to +1 of -1 , depending of the position of the object.

Parameters:
o_pos - Position of the object
radius - Radius of the object
normal - Resulting steering force in local coordinates
Returns:
-1 if no intersection, minimum x position if intersection

xaxis_poly_intersect

protected double xaxis_poly_intersect(Vehicle v,
                                      Vector2d normal)
xaxis_poly_intersect Test a polygon for intersection with the local x axis of the vehicle. Returns -1 if there is no intersection else returns the x position of the intersection point. The normal parameter is set to the nromal vector of the line segment at the intersection point in vehicle coordinates.

Parameters:
v - Our vehicle
normal - [Out ]Resulting steering force in local coordinates
Returns:
-1 if no intersection, minimum x position if intersection

xaxis_rect_intersect

protected double xaxis_rect_intersect(Vehicle v,
                                      Point2d o_pos,
                                      Point2d p1,
                                      Point2d p2,
                                      Point2d p3,
                                      Point2d p4,
                                      Vector2d normal)
xaxis_rect_intersect Tests a rectangle for intersection with the local x axis. Returns -1 if there is no intersection, otherwise the x positon of the intersection is returned and the normal parameter is set to the surface normal at the intersection.

Parameters:
v - Our vehicle
o_pos - Position of the obstacle
p1 - Rectangle point: left up
p2 - Rectangle point: right up
p3 - Rectangle point: right down
p4 - Rectangle point: left down
normal - Returns the normal vector used for steering
Returns:
-1 if no intersection, minimum x position if intersection