crowdmodel.utils
Class MathUtils

java.lang.Object
  extended by crowdmodel.utils.MathUtils

public class MathUtils
extends java.lang.Object

Class that describes static method functions = functions that do not need a class instantiation to be used = mathematical functions that are convenient for my model, however are not part of the model

Author:
Nanda Wijermans

Constructor Summary
MathUtils()
           
 
Method Summary
static double AngleAddition(double angle0, double angle1)
          Adds two angles with each other and corrects for non-existing angles [0-360] Repast corrects itself for this.
static double AngleSubtraction(double angle0, double angle1)
          Subtracts two angles with each other and corrects for non-existing angles [0-360]
static double calcArea(double angle, double az)
          Function calculates the area of a triangle Calculates the opposite, given the angle and Adjacent side opposite = tan(angle/2) * adjacent area = 2(opposite * adjacent)
static double calcHeading(double heading, repast.simphony.space.continuous.NdPoint pos1, repast.simphony.space.continuous.NdPoint pos2)
          Calculates what the heading(angle) is given a position and the heading to the new heading should be, given a point it should be directed to In repast the coordinate system allows mixed ranges: - from 0 (top), 90 (right), 180/-180 (bottom), -90 (left)
static repast.simphony.space.continuous.NdPoint calcNewPosition(double x, double y, double v, double heading)
          Calculates a new position (NdPoint) on the continuous space Given the current position, heading and speed.
static double dist(double v)
          Calculates the transposition (the distance in moving given a certain velocity) returns the distance in terms of simulation distance given a velocity in real (m/s) terms Physical space is related to a real physical space 1 grid cell / unit = 40x40cm (0.4x0.4m) movement of 1 is 40cm in real v [m/s] = [2.5 unit / s] // need to think how simulation time relates to real time
static double getAngleDiff(double h0, double h1)
          Returns the angle between two headings (in degrees) this is used to see whether a specific agent is positioned within a certain gaze-width
static double getDistance(repast.simphony.space.continuous.NdPoint pos1, repast.simphony.space.continuous.NdPoint pos2)
          Returns the distance between two NdPoints
static double getMax(double[] ar)
          returns the maximal value of an double array.
static int getMax(int[] ar)
          returns the maximal value of an Integer array.
static int getMaxIndex(double[] ar)
          Returns the index of the maximum value given an array of values
static int getMin(int[] ar, int length)
          getMin returns the minimal value of an Integer array.
static int[] getMinAndMax(int[] ar)
          getMinAndMax returns the min and max value of an Integer array.
static int[] getMinAndMax(int[] ar, int length)
          Overloaded function that returns the min and max value of an Integer array.
static boolean withinLineOfSight(double myheading, double alpha, double gazeWidth)
          Function that decides whether a heading (beta) lies within line of sight given a current heading (myheading) and a range inbetween the value is supposed to lie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathUtils

public MathUtils()
Method Detail

getDistance

public static double getDistance(repast.simphony.space.continuous.NdPoint pos1,
                                 repast.simphony.space.continuous.NdPoint pos2)
Returns the distance between two NdPoints


calcHeading

public static double calcHeading(double heading,
                                 repast.simphony.space.continuous.NdPoint pos1,
                                 repast.simphony.space.continuous.NdPoint pos2)
Calculates what the heading(angle) is given a position and the heading to the new heading should be, given a point it should be directed to In repast the coordinate system allows mixed ranges: - from 0 (top), 90 (right), 180/-180 (bottom), -90 (left). - [0,360] - [0,infinite] Here we choose to generate the angles within the range [0,360] The heading is calculated as follows:

Based on the relative position from one point A (me) to another point B(other) there are either positioned: I) on the same axe (either: left, right, top or bottom position)
II) in one of the Quadrants (1,2,3,4)

Given the distances (height and width of a vector between the points) and the quadrants the other point can lie in relative from point A (me)
deltaX = x1 (me) - x2 (other)
deltaY = x2 (me) - y2 (other)

Quadrant 1 (Q1): top-right, (deltaX < 0 && deltaY < 0)
Quadrant 2 (Q2): top-left, (deltaX > 0 && deltaY < 0)
Quadrant 3 (Q3): bottom-left, deltaX > 0 && deltaY < 0)
Quadrant 4 (Q4): bottom-right, deltaX < 0 && deltaY < 0)

In condition I :
If deltaX == 0 : point B is on the same vertical height.
    • if deltaY > 0 : heading = 180, B is above A
      if deltaY < 0 : heading = 0, B is below A
  • else if deltaY == 0 : point be is on the same horizontal height
    • if deltaX > 0 : heading = 270, B is left from A
      if deltaX < 0 : heading = 90, B is right from A
  • The angle is calculated in the same way for each B, independent from the quadrant B is situated in. To calculate the heading is based on the the quadrant the other point is lying in.

    alpha = shift tan(deltaX / deltaY) Q1: heading = alpha Q2: heading = 180 - alpha Q3: heading = 180 + alpha Q4: heading = 360 - alpha

    Parameters:
    pos1 - - my position (A)
    pos2 - - position where I am heading to (B)

    withinLineOfSight

    public static boolean withinLineOfSight(double myheading,
                                            double alpha,
                                            double gazeWidth)
    Function that decides whether a heading (beta) lies within line of sight given a current heading (myheading) and a range inbetween the value is supposed to lie. It assumes heading values between [0,360].

    Parameters:
    myheading -
    alpha -
    gazeWidth -
    Returns:
    whether a value lies within a certain range

    getAngleDiff

    public static double getAngleDiff(double h0,
                                      double h1)
    Returns the angle between two headings (in degrees) this is used to see whether a specific agent is positioned within a certain gaze-width


    AngleAddition

    public static double AngleAddition(double angle0,
                                       double angle1)
    Adds two angles with each other and corrects for non-existing angles [0-360] Repast corrects itself for this.

    Parameters:
    angle0 -
    angle1 -
    Returns:
    added angles within the[0-360] boundary

    AngleSubtraction

    public static double AngleSubtraction(double angle0,
                                          double angle1)
    Subtracts two angles with each other and corrects for non-existing angles [0-360]

    Parameters:
    angle0 -
    angle1 -
    Returns:
    added angles within the[0-360] boundary

    calcNewPosition

    public static repast.simphony.space.continuous.NdPoint calcNewPosition(double x,
                                                                           double y,
                                                                           double v,
                                                                           double heading)
    Calculates a new position (NdPoint) on the continuous space Given the current position, heading and speed.


    dist

    public static double dist(double v)
    Calculates the transposition (the distance in moving given a certain velocity) returns the distance in terms of simulation distance given a velocity in real (m/s) terms Physical space is related to a real physical space 1 grid cell / unit = 40x40cm (0.4x0.4m) movement of 1 is 40cm in real v [m/s] = [2.5 unit / s] // need to think how simulation time relates to real time


    getMin

    public static int getMin(int[] ar,
                             int length)
    getMin returns the minimal value of an Integer array.


    getMax

    public static int getMax(int[] ar)
    returns the maximal value of an Integer array. overloaded function (for double arrays)

    Parameters:
    ar, - length
    Returns:
    max

    getMax

    public static double getMax(double[] ar)
    returns the maximal value of an double array. overloaded function (for integer arrays)

    Parameters:
    ar -
    Returns:
    max value in array

    getMaxIndex

    public static int getMaxIndex(double[] ar)
    Returns the index of the maximum value given an array of values

    Parameters:
    ar -
    length -
    Returns:
    index of the largest value in an array

    getMinAndMax

    public static int[] getMinAndMax(int[] ar)
    getMinAndMax returns the min and max value of an Integer array. Also in this order: ar[0] = min, ar[1] = max This is a bit more efficient if one needs min and max values in an array.


    getMinAndMax

    public static int[] getMinAndMax(int[] ar,
                                     int length)
    Overloaded function that returns the min and max value of an Integer array. Overloaded because in some cases not the whole array needs to be considered such as in Area to look at the points in a Polygon

    Parameters:
    ar -
    length -
    Returns:

    calcArea

    public static double calcArea(double angle,
                                  double az)
    Function calculates the area of a triangle Calculates the opposite, given the angle and Adjacent side opposite = tan(angle/2) * adjacent area = 2(opposite * adjacent)

    Parameters:
    angle - - in degrees
    az - - adjacent side
    Returns:
    area