public class LineSegment extends Object implements IPlaneObject
A line segment is defined by its two end points.
Constructor and Description |
---|
LineSegment(YPoint p1,
YPoint p2)
Returns a new LineSegment.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
boxIntersectsSegment(double boxX1,
double boxY1,
double boxX2,
double boxY2,
double sX1,
double sY1,
double sX2,
double sY2)
Checks whether a line segment intersects a paraxial box.
|
static boolean |
boxIntersectsSegment(YRectangle box,
double x1,
double y1,
double x2,
double y2)
Checks whether a line segment intersects a box.
|
static boolean |
boxIntersectsSegment(YRectangle box,
YPoint s,
YPoint t)
Checks whether a line segment intersects a box.
|
boolean |
contains(YPoint point)
Checks whether a given point lies on this line segment.
|
YRectangle |
getBoundingBox()
Gets the smallest Rectangle which contains the object.
|
double |
getDeltaX()
Gets the distance from start to end point in x-coordinates.
|
double |
getDeltaY()
Gets the distance from start to end point in y-coordinates.
|
YPoint |
getFirstEndPoint()
Gets the first end point of the line segment.
|
static YPoint |
getIntersection(LineSegment s1,
LineSegment s2)
Returns intersection point between the two line segments, if there is one or
null if the two line segments do
not intersect. |
YPoint |
getSecondEndPoint()
Gets the second end point of the line segment.
|
double |
getSlope()
Gets the slope of the line segment.
|
double |
getXOffset()
Gets the y value of the line on x coordinate 0.
|
boolean |
intersects(YPoint p)
Checks whether the line segment intersects a point.
|
boolean |
intersects(YRectangle box)
Checks whether the line segment intersects a box.
|
boolean |
isHorizontal()
Gets if the interval is horizontal.
|
static boolean |
isHorizontal(YPoint p1,
YPoint p2)
Determines if the given points define a horizontal line segment.
|
boolean |
isInXIntervall(double x)
Returns if the projection on the X axis of the line segment covers a certain point on the X Axis.
|
boolean |
isInYIntervall(double y)
Returns if the projection on the Y axis of the line segment covers a certain point on the Y Axis.
|
boolean |
isVertical()
Gets if this segment is considered vertical, i.e.
|
static boolean |
isVertical(YPoint p1,
YPoint p2)
Determines if the given points define a vertical line segment.
|
double |
length()
Returns the length of the line segment, this is the value of the Euclidean norm.
|
AffineLine |
toAffineLine()
Returns the affine line defined by the end points of the line segment.
|
String |
toString()
String representation of the line.
|
YVector |
toYVector()
Returns the vector pointing from the first end point to the second end point of the line segment.
|
public static final boolean boxIntersectsSegment(double boxX1, double boxY1, double boxX2, double boxY2, double sX1, double sY1, double sX2, double sY2)
Implemented using the Cohen-Sutherland algorithm.
boxX1
- x-coordinate of the upper left corner of the boxboxY1
- y-coordinate of the upper left corner of the boxboxX2
- x-coordinate of the lower right corner of the boxboxY2
- y-coordinate of the lower right corner of the boxsX1
- x-coordinate of the first end point of the line segmentsY1
- y-coordinate of the first end point of the line segmentsX2
- x-coordinate of the second end point of the line segmentsY2
- y-coordinate of the second end point of the line segmenttrue
if the line segment intersects the box, false
otherwise.public static final boolean boxIntersectsSegment(YRectangle box, double x1, double y1, double x2, double y2)
Implemented using the Cohen-Sutherland algorithm.
box
- A rectanglex1
- x-coordinate of the first end point of the line segmenty1
- y-coordinate of the first end point of the line segmentx2
- x-coordinate of the second end point of the line segmenty2
- y-coordinate of the second end point of the line segmenttrue
if the line segment intersects the box, false
otherwise.public static final boolean boxIntersectsSegment(YRectangle box, YPoint s, YPoint t)
box
- A rectangle.s
- first end point of the line segment.t
- second end point of the line segment.true
if the line segments intersects the box, false
otherwise.public boolean contains(YPoint point)
point
- an arbitrary point.true
if the line segments intersects the box, false
otherwise.public YRectangle getBoundingBox()
getBoundingBox
in interface IPlaneObject
public double getDeltaX()
public double getDeltaY()
public YPoint getFirstEndPoint()
public static final YPoint getIntersection(LineSegment s1, LineSegment s2)
null
if the two line segments do
not intersect.s1
- first line segments2
- second line segmentpublic YPoint getSecondEndPoint()
public double getSlope()
public double getXOffset()
public boolean intersects(YPoint p)
p
- a pointtrue
if the line segments intersects the given point, false
otherwise.public boolean intersects(YRectangle box)
box
- A rectangle.true
if the line segments intersects the box, false
otherwise.public boolean isHorizontal()
true
if the interval is horizontal, false
otherwise.public static final boolean isHorizontal(YPoint p1, YPoint p2)
This methods allows for y-coordinate differences of up to 1e-8.
true
if the given points define a horizontal line segment; false
otherwise.public boolean isInXIntervall(double x)
public boolean isInYIntervall(double y)
public boolean isVertical()
the x values of the end point differ less then 0.00000001
true
if this segment is considered vertical, false
otherwise.public static final boolean isVertical(YPoint p1, YPoint p2)
This methods allows for x-coordinate differences of up to 1e-8.
true
if the given points define a vertical line segment; false
otherwise.public double length()
public AffineLine toAffineLine()
public String toString()
public YVector toYVector()