|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object vanetsim.map.MapHelper
public final class MapHelper
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.
Constructor Summary | |
---|---|
MapHelper()
|
Method Summary | |
---|---|
static void |
calculateBridges(Street bridgeStreet,
Street otherStreet)
Checks for intersections on the maps and creates bridges if necessary (only for display purposes). |
static double |
calculateDistancePointToStreet(Street street,
int x,
int y,
boolean sqrt,
int[] result)
Calculate the distance between a point and a street. |
static void |
calculateResizedLine(int[] startPoint,
int[] endPoint,
double correction,
boolean correctStart,
boolean correctEnd)
Recalculates start and end points of a line so that the line is shorter or longer than before. |
static int |
findLineCircleIntersections(int circleX,
int circleY,
int circleRadius,
int x1,
int y1,
int x2,
int y2,
boolean onlyOnSegment,
int[] result)
Finds an intersection between a line and a circle. |
static Node |
findNearestNode(int x,
int y,
int maxDistance,
long[] distance)
Returns the nearest node to a given point. |
static boolean |
findNearestPointOnStreet(Street street,
int x,
int y,
int[] result)
Calculates the point ON a street which is nearest to a given point (for snapping or such things). |
static Street |
findNearestStreet(int x,
int y,
int maxDistance,
double[] distance,
int[] nearestPoint)
Returns the nearest street to a given point. |
static Vehicle |
findNearestVehicle(int x,
int y,
int maxDistance,
long[] distance)
Returns the nearest vehicle to a given point. |
static boolean |
findSegmentIntersection(int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4,
double[] result)
Finds an intersection between two segments. |
static boolean |
getXYParallelRight(int x1,
int y1,
int x2,
int y2,
int distance,
double[] result)
Gets the x and y coordinate difference of a parallel line on the right side (seen from first point to second point). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MapHelper()
Method Detail |
---|
public static double calculateDistancePointToStreet(Street street, int x, int y, boolean sqrt, int[] result)
street
- the street givenx
- x coordinate of the pointy
- y coordinate of the pointsqrt
- if 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!)result
- an 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)!
double
. If nothing was found, Double.MAX_VALUE
is returned.public static boolean findNearestPointOnStreet(Street street, int x, int y, int[] result)
street
- the streetx
- the x coordinate of the pointy
- the y coordinate of the pointresult
- an 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!
true
if calculation was successful, else false
public static Street findNearestStreet(int x, int y, int maxDistance, double[] distance, int[] nearestPoint)
maxDistance
. Then, ALL
streets in these regions are checked if they are within this maxDistance
and the best one is returned (if any exists).
x
- the x coordinate of the given pointy
- the x coordinate of the given pointmaxDistance
- the 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!distance
- an array used to return the distance between the nearest point and the point given. This should be a double[1]
array!nearestPoint
- an array used to return the x-coordinate (nearestpoint[0]
) and y-coordinate (nearestpoint[1]
)
on the street.
null
if none was found or an error occuredpublic static Vehicle findNearestVehicle(int x, int y, int maxDistance, long[] distance)
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!
x
- the x coordinate of the given pointy
- the x coordinate of the given pointmaxDistance
- the 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!distance
- an array used to return the distance between the nearest point and the point given. This should be a long[1]
array!
null
if none was found or an error occuredpublic static Node findNearestNode(int x, int y, int maxDistance, long[] distance)
maxDistance
. Then, ALL
nodes in these regions are checked if they are within this maxDistance
and the best one is returned (if any exists).
x
- the x coordinate of the given pointy
- the x coordinate of the given pointmaxDistance
- the 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!distance
- an array used to return the distance between the nearest point and the point given. This should be a long[1]
array!
null
if none was found or an error occuredpublic static boolean findSegmentIntersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double[] result)
x1
- the x coordinate of the first point of the first segmenty1
- the y coordinate of the first point of the first segmentx2
- the x coordinate of the second point of the first segmenty2
- the y coordinate of the second point of the first segmentx3
- the x coordinate of the first point of the second segmenty3
- the y coordinate of the first point of the second segmentx4
- the x coordinate of the second point of the second segmenty4
- the y coordinate of the second point of the second segmentresult
- an array to return the intersection point. The x coordinate will be in result[0]
,
the y coordinate in result[1]
.
true
if lines intersect, false
if lines don't intersect or if you didn't supply
a valid result
array.public static int findLineCircleIntersections(int circleX, int circleY, int circleRadius, int x1, int y1, int x2, int y2, boolean onlyOnSegment, int[] result)
circleX
- The x coordinate of the middle of the circlecircleY
- The y coordinate of the middle of the circlecircleRadius
- The radius of the circlex1
- The x coordinate of the start point of the liney1
- The y coordinate of the start point of the linex2
- The x coordinate of the end point of the liney2
- The y coordinate of the end point of the lineonlyOnSegment
- If true
, only intersection points are found which are on the line segment, else intersections on the extension
of the line segment are also found!result
- An 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]
.
public static boolean getXYParallelRight(int x1, int y1, int x2, int y2, int distance, double[] result)
x1
- the x coordinate of the first pointy1
- the y coordinate of the first pointx2
- the x coordinate of the second pointy2
- the y coordinate of the second pointdistance
- the distanceresult
- an 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]
.
true
if calculation was successful, else false
public static void calculateBridges(Street bridgeStreet, Street otherStreet)
lowerspeedStreet
.
This function takes quite a long time to process if the map is large.
bridgeStreet
- the street which will be above otherStreet
if both intersectotherStreet
- the other streetpublic static void calculateResizedLine(int[] startPoint, int[] endPoint, double correction, boolean correctStart, boolean correctEnd)
startPoint
- the start point. x coordinate is expected in startPoint[0]
, y in startPoint[1]
.
Will be used to return the result.endPoint
- the end point. x coordinate is expected in endPoint[0]
, y in endPoint[1]
.
Will be used to return the result.correction
- the 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.correctStart
- if the startPoint
shall be corrected.correctEnd
- if the endPoint
shall be corrected.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |