|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrobocode.util.Collision
public class Collision
This class contains more advanced collision detection methods then the original Robocode has. It also contains some helper methods to make the job slightly easier.
Constructor Summary | |
---|---|
Collision()
|
Method Summary | |
---|---|
static boolean |
collide(ITransformable p0,
ITransformable p1)
Determines whether two robots collided. |
static boolean |
collide(ITransformable p,
Line2D.Double l)
Determines whether the robot collides with a Line2D.Double . |
static boolean |
collide(ITransformable p,
Rectangle2D rectangle)
THOMA: STILL NEEDS A FEW JUNIT TESTS Collision method that is mainly used for mines. |
static boolean |
collide(Line2D.Double lineA,
Line2D.Double lineB)
Determines whether the Line2D.Double
intersect with each other. |
protected static HashMap<Integer,List<Integer>> |
collisionPointsPolygon(Polygon p0,
Polygon p1)
Returns a HashMap with a list of Integers in it. |
protected static ArrayList<Point> |
distinct(ITransformable peer)
Generates a list of distinct points from the bounding box of a robot. |
protected static ArrayList<Point> |
distinct(Polygon p)
Generates a list of distinct points from a polygon . |
static Map<Integer,List<Integer>> |
getCollisionPoints(ITransformable p0,
ITransformable p1)
Returns a List with all the points of collision. |
protected static Polygon |
getPolygon(Arc2D a,
AffineTransform at)
Generates a Polygon that resembles the given
Arc2D ,
when the given AffineTransform is applied. |
static Polygon |
getPolygon(ITransformable peer)
Get the polygon of a peer. |
static Polygon |
getPolygon(Rectangle2D r,
AffineTransform at)
Generates a polygon that resembles the given
rectangle ,
when the given transformation is applied. |
static Rectangle2D |
getRectangle(ITransformable peer)
Get the bounding box rectangle for the specified robot. |
protected static boolean |
insidePolygon(ITransformable peer,
Line2D.Double line)
Determines whether the line
is inside the polygon of the peer. |
static boolean |
insidePolygon(Polygon p0,
Polygon p1)
|
static boolean |
insideScan(Arc2D a,
double x,
double y)
Determines whether or not the projectile is inside the scan arc. |
static boolean |
insideScan(Arc2D a,
ITransformable peer)
Determines whether or not the peer is inside the shape. |
protected static boolean |
intersect(Line2D.Double lineA,
Line2D.Double lineB)
Determines whether two (straight) lines intersect with each other. |
protected static boolean |
intersect(Rectangle2D r,
AffineTransform at,
Line2D.Double line)
Determines whether the rectangle and
line intersect with each other. |
protected static boolean |
intersect(Rectangle2D r0,
AffineTransform at0,
Rectangle2D r1,
AffineTransform at1)
Determines whether two rectangles
intersect with each other. |
protected static boolean |
intersectLine(Polygon p,
Line2D.Double lineA)
Determines whether the line
intersects with the polygon . |
protected static boolean |
intersectPolygon(Polygon p0,
Polygon p1)
Determines whether two polygons intersect with each other. |
static Polygon |
rectangleToPolygon(Rectangle2D rectangle)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Collision()
Method Detail |
---|
protected static final boolean intersect(Line2D.Double lineA, Line2D.Double lineB)
Line2D.linesIntersect
which returns an incorrect value on certain versions of Java. This is
confirmed to be at least the case in Java 5. (Status as of writing is
still unresolved!)
lineA
- The first of the two lines that has to intersect.lineB
- The second of the two lines that has to intersect.
true
if the lines intersect with one another; false
otherwise.public static final Polygon getPolygon(Rectangle2D r, AffineTransform at)
polygon
that resembles the given
rectangle
,
when the given transformation
is applied.
r
- The rectangle on which the transformation has to take place.at
- The transformation to apply.
Polygon
representing the transformed rectangle.protected static final Polygon getPolygon(Arc2D a, AffineTransform at)
Polygon
that resembles the given
Arc2D
,
when the given AffineTransform
is applied.
a
- The Arc2D
on which the transformation has to take place.at
- The AffineTransform
to apply to the Arc2D
.
Polygon
representing the transformed rectangle.protected static final ArrayList<Point> distinct(ITransformable peer)
peer
- The peer from whom to get the distinct points of its bounding box.
ArrayList<Point>
containing the distinct points
of a robot's bounding box.protected static final ArrayList<Point> distinct(Polygon p)
polygon
.
p
- The polygon from whom to get the points.
ArrayList<Point>
containing the distinct points of a polygon.protected static final boolean intersectLine(Polygon p, Line2D.Double lineA)
line
intersects with the polygon
.
p
- The polygon that has the intersect.lineA
- The line that has to intersect the polygon.
true
when the polygon and line intersect. false
otherwise.protected static final boolean insidePolygon(ITransformable peer, Line2D.Double line)
line
is inside the polygon of the peer.
peer
- The peer that should contain the line.line
- The line that should be inside the polygon.
true
when the line is inside the polygon. false
otherwise.protected static final boolean intersectPolygon(Polygon p0, Polygon p1)
polygons
intersect with each other.
p0
- The first polygon that has to intersect.p1
- The second polygon that has to intersect.
true
when the polygons intersect.protected static final HashMap<Integer,List<Integer>> collisionPointsPolygon(Polygon p0, Polygon p1)
p0
- "Ship1" It's the Polygon you will get the collision points ofp1
- "Ship2" The Polygon colliding with p0
protected static final boolean intersect(Rectangle2D r, AffineTransform at, Line2D.Double line)
rectangle
and
line
intersect with each other.
The transformation of the rectangle will be applied before
determining whether the rectangle and line intersect!
r
- The rectangle that has to intersect with the line.at
- The transformation that has to be applied to the rectangle.line
- The line that has to intersect with the rectangle.
true
when the rectangle and line intersect.protected static final boolean intersect(Rectangle2D r0, AffineTransform at0, Rectangle2D r1, AffineTransform at1)
rectangles
intersect with each other.
r0
- The first rectangle that has to intersect.at0
- The transformation of the first rectangle.r1
- The second rectangle that has to intersect.at1
- The transformation of the second rectangle.
true
when the two rectangles intersect; false
otherwise.public static final boolean collide(ITransformable p0, ITransformable p1)
p0
- The first robot that has to collide.p1
- The second robot that has to collide.
true
when the robots collide. false
otherwise.public static Map<Integer,List<Integer>> getCollisionPoints(ITransformable p0, ITransformable p1)
p0
- The Peer we want to check the Collision ofp1
- The Peer that collides with the above peer
public static final boolean insideScan(Arc2D a, ITransformable peer)
a
- The scan arc of the ship's radar.peer
- The peer that may be spotted by the radar.
true
when the ship is inside the arc. false
otherwise.public static final boolean insideScan(Arc2D a, double x, double y)
a
- The scan arc that should scan the projectile.projectile
- The projectile that has to be scanned.
true
if the projectile got scanned; false
otherwise.public static final boolean collide(ITransformable p, Line2D.Double l)
Line2D.Double
.
p
- The peer that has to collide.l
- The line that has to collide with the peer.
true
when the peer and the line collide. false
otherwise.public static final boolean collide(Line2D.Double lineA, Line2D.Double lineB)
Line2D.Double
intersect with each other.
lineA
- The first line that has to intersect.lineB
- The second line that has to intersect.
true
when the lines intersect. false
otherwise.public static final boolean collide(ITransformable p, Rectangle2D rectangle)
p
- rectangle
-
public static boolean insidePolygon(Polygon p0, Polygon p1)
public static Polygon rectangleToPolygon(Rectangle2D rectangle)
public static final Rectangle2D getRectangle(ITransformable peer)
peer
- The robot from whom to get the bounding box rectangle.
Rectangle2D
public static final Polygon getPolygon(ITransformable peer)
peer
- The peer to get the polygon from.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |