Class Line
public class Line
extends java.lang.Object
You should NOT use the Line class as a method of measuring the distance between two points. Rather, the Distance class has a lovely little static method named "getDistance" that'll do exactly that for you.
Lines are a core component of many shapes, namely rectangles and squares. Aside from using those shapes, it's fairly unlikely you're going to need to use this class. But it's here anyways!
- Since:
- 0.1.0
- Author:
- Colin Robertson
-
Field Summary
Fields Modifier and Type Field Description private Point
a
One of the two points of a line.private Point
aPoint
The midpoint between the midpoint and A.private Point
b
One of the two points of a line.private Point
bPoint
The midpoint between the midpoint and B.private Point
midpoint
The midpoint of the line. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description static boolean
doesIntersect(Line a, Line b)
Check whether or not two lines collide at any point.Point
getA()
Get the A point.Point
getAPoint()
Get the point between A and the midpoint.Point
getB()
Get the B point.Point
getBPoint()
Get the point between B and the midpoint.double
getLength()
Get the length of the line, in units.Point
getMidpoint()
Get the midpoint.boolean
isPointOnLine(Point point)
Check whether or not a given ordered pair lies on the instanced line.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
a
One of the two points of a line. -
b
One of the two points of a line. -
midpoint
The midpoint of the line. -
aPoint
The midpoint between the midpoint and A. -
bPoint
The midpoint between the midpoint and B.
-
-
Constructor Details
-
Line
Create a new line.Lines have five major points:
- A (you provide this one)
- B (you provide this one)
- Midpoint (in between A and B)
- A-Point (in between A and the midpoint)
- B-Point (in between B and the midpoint)
- Parameters:
a
- one of the line's two points.b
- one of the line's two points.
-
Line
Create a new line from a center point, extending outwards at a given angle for a given length.Lines have five major points:
- A (you provide this one)
- B (you provide this one)
- Midpoint (in between A and B)
- A-Point (in between A and the midpoint)
- B-Point (in between B and the midpoint)
- Parameters:
a
- the line's center-point.angle
- the angle at which the line should be drawn.length
- the length of the line to draw.
-
-
Method Details
-
getA
Get the A point.- Returns:
- the A point.
-
getB
Get the B point.- Returns:
- the B point.
-
getMidpoint
Get the midpoint.- Returns:
- the midpoint.
-
getAPoint
Get the point between A and the midpoint.- Returns:
- the point between A and the midpoint.
-
getBPoint
Get the point between B and the midpoint.- Returns:
- the point between B and the midpoint.
-
getLength
public double getLength()Get the length of the line, in units.Mapping has nothing to do with units - whatever unit you put in, you'll get out.
- Returns:
- the length of the line in (?) units.
-
doesIntersect
Check whether or not two lines collide at any point.Prior to reaching this stage of virtual collision detection, check to make sure none of the following conditions are true...
- Lines are parallel.
- Line intersection is theoretically impossible due to distance.
- Line intersection is, for another reason, theoretically impossible.
A, B, and C are numbers which define each of the lines. Given two sets of points, (x1, y1) and (x2, y2) we can determine the point of intersection between the two lines. After finding this point of intersection, however, we still have to make sure that that point of intersection is actually on both of the lines, ensuring a virtual collision is indeed happening.
A = y2-y1; B = x1-x2; C = Ax1+By1;
- Parameters:
a
- the first lineb
- the second line- Returns:
- whether or not the lines intersect
-
isPointOnLine
Check whether or not a given ordered pair lies on the instanced line."If your line segment goes from (x1, y1) to (x2, y2), then to check if (x, y) is on that segment, you just need to check that min(x1, x2) <= x <= max(x1, x2), and do the same thing for Y."
In order to check whether or not two lines collide at any point, we have to first ensure that there is indeed a point of collision. This may, in the near future, need to be adjusted using comparators to allow for certain degrees of tolerance to ensure that points are very nearly on the line rather than on the line - simply checking if a point is on a given line could sometimes be inaccurate.
- Parameters:
point
- a given pair- Returns:
- whether or not that point is on this line
-