VANET Simulator
 All Classes Functions Variables
Static Public Member Functions | List of all members
vanetsim.map.MapHelper Class Reference

Static Public Member Functions

static double calculateDistancePointToStreet (Street street, int x, int y, boolean sqrt, int[] result)
 
static boolean findNearestPointOnStreet (Street street, int x, int y, int[] result)
 
static Street findNearestStreet (int x, int y, int maxDistance, double[] distance, int[] nearestPoint)
 
static Vehicle findNearestVehicle (int x, int y, int maxDistance, long[] distance)
 
static Node findNearestNode (int x, int y, int maxDistance, long[] distance)
 
static boolean findSegmentIntersection (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double[] result)
 
static int findLineCircleIntersections (int circleX, int circleY, int circleRadius, int x1, int y1, int x2, int y2, boolean onlyOnSegment, int[] result)
 
static boolean getXYParallelRight (int x1, int y1, int x2, int y2, int distance, double[] result)
 
static void calculateBridges (Street bridgeStreet, Street otherStreet)
 
static void calculateResizedLine (int[] startPoint, int[] endPoint, double correction, boolean correctStart, boolean correctEnd)
 

Detailed Description

This class holds some geometric functions needed for various calculations on the map. It's just a helper class to make the map class smaller and as this class has no variables, all functions are declared static.

Member Function Documentation

static void vanetsim.map.MapHelper.calculateBridges ( Street  bridgeStreet,
Street  otherStreet 
)
inlinestatic

Checks for intersections on the maps and creates bridges if necessary (only for display purposes). The bridge is added to the lowerspeedStreet. This function takes quite a long time to process if the map is large.

Parameters
bridgeStreetthe street which will be above otherStreet if both intersect
otherStreetthe other street
static double vanetsim.map.MapHelper.calculateDistancePointToStreet ( Street  street,
int  x,
int  y,
boolean  sqrt,
int[]  result 
)
inlinestatic

Calculate the distance between a point and a street.

Parameters
streetthe street given
xx coordinate of the point
yy coordinate of the point
sqrtif set to true, the correct distance is returned; if set to false the square of the distance is returned (little bit faster as it saves a call to Math.sqrt(); however, use only if you can handle this!)
resultan array holding the point on the street so that it can be returned. result[0] holds the x coordinate, result[1] the y coordinate. Make sure the array has the correct size (2 elements)!
Returns
the distance as a double. If nothing was found, Double.MAX_VALUE is returned.
static void vanetsim.map.MapHelper.calculateResizedLine ( int[]  startPoint,
int[]  endPoint,
double  correction,
boolean  correctStart,
boolean  correctEnd 
)
inlinestatic

Recalculates start and end points of a line so that the line is shorter or longer than before.

Parameters
startPointthe start point. x coordinate is expected in startPoint[0], y in startPoint[1]. Will be used to return the result.
endPointthe end point. x coordinate is expected in endPoint[0], y in endPoint[1]. Will be used to return the result.
correctionthe amount of length correction. Use a positive value to makes the line shorter, a negative to make it longer. If correctStart and correctEnd are both true, the total correction is double of this value, if both are false no correction is done.
correctStartif the startPoint shall be corrected.
correctEndif the endPoint shall be corrected.
static int vanetsim.map.MapHelper.findLineCircleIntersections ( int  circleX,
int  circleY,
int  circleRadius,
int  x1,
int  y1,
int  x2,
int  y2,
boolean  onlyOnSegment,
int[]  result 
)
inlinestatic

Finds an intersection between a line and a circle. Code basically from VB Helper: Find the points where a line intersects a circle in Visual Basic .NET (link last visited: 31.10.2008).

Parameters
circleXThe x coordinate of the middle of the circle
circleYThe y coordinate of the middle of the circle
circleRadiusThe radius of the circle
x1The x coordinate of the start point of the line
y1The y coordinate of the start point of the line
x2The x coordinate of the end point of the line
y2The y coordinate of the end point of the line
onlyOnSegmentIf true, only intersection points are found which are on the line segment, else intersections on the extension of the line segment are also found!
resultAn array to return the result. Should be an int[4]. The x coordinate of the first point will be in result[0], the y coordinate in result[1]. The x coordinate of the second point will be in result[2], the y coordinate in result[3].
Returns
The amount of intersections found (0-2).
static Node vanetsim.map.MapHelper.findNearestNode ( int  x,
int  y,
int  maxDistance,
long[]  distance 
)
inlinestatic

Returns the nearest node to a given point. First all regions are calculated which are within maxDistance. Then, ALL nodes in these regions are checked if they are within this maxDistance and the best one is returned (if any exists).

Parameters
xthe x coordinate of the given point
ythe x coordinate of the given point
maxDistancethe maximum distance; use Integer.MAX_VALUE if you just want to get any nearest vehicle but note that this costs a lot of performance because ALL regions and ALL nodes are checked!
distancean array used to return the distance between the nearest point and the point given. This should be a long[1] array!
Returns
the nearest node or null if none was found or an error occured
static boolean vanetsim.map.MapHelper.findNearestPointOnStreet ( Street  street,
int  x,
int  y,
int[]  result 
)
inlinestatic

Calculates the point ON a street which is nearest to a given point (for snapping or such things). This code was inspired by Paul Bourke's homepage, especially the Delphi sourcecode (link last visited on 15.08.2008). See there for the mathematical background of this calculation!

Parameters
streetthe street
xthe x coordinate of the point
ythe y coordinate of the point
resultan array for the result. result[0] holds the x coordinate, result[1] the y coordinate. Make sure the array has the correct size (2 elements), otherwise you will not get a result!
Returns
true if calculation was successful, else false
static Street vanetsim.map.MapHelper.findNearestStreet ( int  x,
int  y,
int  maxDistance,
double[]  distance,
int[]  nearestPoint 
)
inlinestatic

Returns the nearest street to a given point. First all regions are calculated which are within maxDistance. Then, ALL streets in these regions are checked if they are within this maxDistance and the best one is returned (if any exists).

Parameters
xthe x coordinate of the given point
ythe x coordinate of the given point
maxDistancethe maximum distance; use Integer.MAX_VALUE if you just want to get any nearest street but note that this costs a lot of performance because ALL regions and ALL streets are checked!
distancean array used to return the distance between the nearest point and the point given. This should be a double[1] array!
nearestPointan array used to return the x-coordinate (nearestpoint[0]) and y-coordinate (nearestpoint[1]) on the street.
Returns
the nearest street or null if none was found or an error occured
static Vehicle vanetsim.map.MapHelper.findNearestVehicle ( int  x,
int  y,
int  maxDistance,
long[]  distance 
)
inlinestatic

Returns the nearest vehicle to a given point. First all regions are calculated which are within maxDistance. Then, ALL vehicles in these regions are checked if they are within this maxDistance and the best one is returned (if any exists). Note that only vehicles which are currently active will be returned!

Parameters
xthe x coordinate of the given point
ythe x coordinate of the given point
maxDistancethe maximum distance; use Integer.MAX_VALUE if you just want to get any nearest vehicle but note that this costs a lot of performance because ALL regions and ALL vehicles are checked!
distancean array used to return the distance between the nearest point and the point given. This should be a long[1] array!
Returns
the nearest street or null if none was found or an error occured
static boolean vanetsim.map.MapHelper.findSegmentIntersection ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  x4,
int  y4,
double[]  result 
)
inlinestatic

Finds an intersection between two segments.
Code basically from CODE & FORM blog from Marius Watz (link last visited: 23.09.2008).

Parameters
x1the x coordinate of the first point of the first segment
y1the y coordinate of the first point of the first segment
x2the x coordinate of the second point of the first segment
y2the y coordinate of the second point of the first segment
x3the x coordinate of the first point of the second segment
y3the y coordinate of the first point of the second segment
x4the x coordinate of the second point of the second segment
y4the y coordinate of the second point of the second segment
resultan array to return the intersection point. The x coordinate will be in result[0], the y coordinate in result[1].
Returns
true if lines intersect, false if lines don't intersect or if you didn't supply a valid result array.
static boolean vanetsim.map.MapHelper.getXYParallelRight ( int  x1,
int  y1,
int  x2,
int  y2,
int  distance,
double[]  result 
)
inlinestatic

Gets the x and y coordinate difference of a parallel line on the right side (seen from first point to second point).

Parameters
x1the x coordinate of the first point
y1the y coordinate of the first point
x2the x coordinate of the second point
y2the y coordinate of the second point
distancethe distance
resultan array to return the coordinate differences of the parallel. The x coordinate difference will be in result[0], the y coordinate difference in result[1].
Returns
true if calculation was successful, else false

The documentation for this class was generated from the following file: