org.jscience.architecture.traffic.util
Class CurveUtils

java.lang.Object
  extended by org.jscience.architecture.traffic.util.CurveUtils

public class CurveUtils
extends java.lang.Object

This class presents methods to handle curves


Constructor Summary
CurveUtils()
           
 
Method Summary
static java.awt.Point calcIntersect(java.awt.Point p1, java.awt.Point p2, double ar1, double ar2)
          Calculate the intersection coordinats for two lines, given a base point and angle for each line.
static double calcLength(TurnCurve c, int step)
          Calculates the length of the specified curve in steps of size step
static int calcPathSteps(TurnCurve c)
          Returns the number of steps used to traverse the specified curve
static TurnCurve createCurve(java.awt.Point p1, java.awt.Point p2, double a1, double a2)
           
static java.awt.geom.GeneralPath createPath(TurnCurve c1, TurnCurve c2)
          Creates a QCurve given two points and angles
static double getAngle(TurnCurve c, int index, int step)
          Returns the angle of a given curve at the given index
static double getCurrentAngle(TurnCurve c, java.awt.Point p)
           
static java.awt.Point getPoint(TurnCurve c, int index, int step)
          Returns the coordinates of the point with specified index and stepsize on a given curve
static int getRoadLength(Road road, int step)
          Returns the length of a given Road.
static double normalize(double a)
          Convert any angle to a value in the range [0, 2Pi]
static void setupRoadSizes(Road road, int step)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CurveUtils

public CurveUtils()
Method Detail

calcIntersect

public static java.awt.Point calcIntersect(java.awt.Point p1,
                                           java.awt.Point p2,
                                           double ar1,
                                           double ar2)
                                    throws CurveException
Calculate the intersection coordinats for two lines, given a base point and angle for each line.

Parameters:
p1 - The base point for the first line
p2 - The base point for the second line
ar1 - The angle of the first line in radians
ar2 - The angle of the second line in radians
Throws:
CurveException

createCurve

public static TurnCurve createCurve(java.awt.Point p1,
                                    java.awt.Point p2,
                                    double a1,
                                    double a2)
                             throws CurveException
Throws:
CurveException

createPath

public static java.awt.geom.GeneralPath createPath(TurnCurve c1,
                                                   TurnCurve c2)
Creates a QCurve given two points and angles

Parameters:
p1 - The coordinats of the first point
p2 - The coordinats of the second point
a1 - The angle of the first point in radians
a2 - The angle of the second point

public static QCurve createCurve(Point p1, Point p2, double a1, double a2) throws CurveException { Point tp = new Point((int)(p1.x + p1.distance(p2) * Math.cos(a1)),(int)(p1.y - p1.distance(p2) * Math.sin(a1))); Rectangle r = new Rectangle(p2.x - 10, p2.y - 10, 20, 20); Point ip; if(r.contains(tp)) return new QCurve(p1,p2); ip = calcIntersect(p1,p2,a1,a2); QCurve c = new QCurve(p1,ip,p2); // test voor path-iterator-bug: Point2D.Double p = c.next(c.getFirst(),2); if(!(c.getBounds().contains(p))) { c = new QCurve(p2,ip,p1); p = c.next(c.getFirst(),2); c.setSwitched(true); } return c; }

/** Creates a GeneralPath connecting both curves in a Drivelane-like fashion

c1 - The first curve
c2 - The second curve
Returns:
A GeneralPath connecting both curves

calcLength

public static double calcLength(TurnCurve c,
                                int step)
Calculates the length of the specified curve in steps of size step

Parameters:
c - The QCurve whose length to calculate
step - The stepsize
Returns:
The length of the specified QCurve

calcPathSteps

public static int calcPathSteps(TurnCurve c)
Returns the number of steps used to traverse the specified curve

Parameters:
c - The QCurve
Returns:
The number of steps

getPoint

public static java.awt.Point getPoint(TurnCurve c,
                                      int index,
                                      int step)
Returns the coordinates of the point with specified index and stepsize on a given curve

Parameters:
c - The curve
step - The stepsize
index - The index of the point
Returns:
The Point at the specified index

getAngle

public static double getAngle(TurnCurve c,
                              int index,
                              int step)
Returns the angle of a given curve at the given index

Parameters:
c - The curve
step - The stepsize
index - The index
Returns:
The angle of the curve at the specified index

getCurrentAngle

public static double getCurrentAngle(TurnCurve c,
                                     java.awt.Point p)

normalize

public static double normalize(double a)
Convert any angle to a value in the range [0, 2Pi]


setupRoadSizes

public static void setupRoadSizes(Road road,
                                  int step)
                           throws InfraException
Throws:
InfraException

getRoadLength

public static int getRoadLength(Road road,
                                int step)
                         throws InfraException
Returns the length of a given Road.

Parameters:
road - A Road
step - The step-size in pixels
Throws:
InfraException