Search this API

## y.geom Class LineSegment

```java.lang.Object y.geom.LineSegment
```
All Implemented Interfaces:
PlaneObject

`public class LineSegmentextends java.lang.Objectimplements PlaneObject`

This class represents a line segment in the plane. A line segment is defined by its two end points.  Constructor Summary
```LineSegment(YPoint p1, YPoint p2)```
Returns a new `LineSegment`.

Method Summary
`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()`
Returns the smallest Rectangle which contains the object.
` double` `getDeltaX()`
Returns the distance from start to end point in x-coordinates.
` double` `getDeltaY()`
Returns the distance from start to end point in y-coordinates.
` YPoint` `getFirstEndPoint()`
Returns 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.
` double` `getScope()`
Returns the slope of the line segment.
` YPoint` `getSecondEndPoint()`
Returns the second end point of the line segment.
` double` `getXOffset()`
Returns 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()`
Returns if this segment is considered horizontal, that is, the y values of the end points differ by at most 1e-8.
`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()`
Returns if this segment is considered vertical, that is, the x values of the end points differ by at most 1e-8.
`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.
` java.lang.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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### LineSegment

```public LineSegment(YPoint p1,
YPoint p2)```
Returns a new `LineSegment`.

Parameters:
`p1` - the first end point of the line segment.
`p2` - the second end point of the line segment.
Method Detail

### isVertical

`public boolean isVertical()`
Returns if this segment is considered vertical, that is, the x values of the end points differ by at most 1e-8.

Returns:
`true` if this segment is considered vertical, `false` otherwise.

### isVertical

```public static boolean isVertical(YPoint p1,
YPoint p2)```
Determines if the given points define a vertical line segment.

This methods allows for x-coordinate differences of up to 1e-8.

Returns:
`true` if the given points define a vertical line segment; `false` otherwise.

### isHorizontal

`public boolean isHorizontal()`
Returns if this segment is considered horizontal, that is, the y values of the end points differ by at most 1e-8.

Returns:
`true` if the segment is considered horizontal, `false` otherwise.

### isHorizontal

```public static boolean isHorizontal(YPoint p1,
YPoint p2)```
Determines if the given points define a horizontal line segment.

This methods allows for y-coordinate differences of up to 1e-8.

Returns:
`true` if the given points define a horizontal line segment; `false` otherwise.

### getFirstEndPoint

`public YPoint getFirstEndPoint()`
Returns the first end point of the line segment.

### getSecondEndPoint

`public YPoint getSecondEndPoint()`
Returns the second end point of the line segment.

### isInYIntervall

`public boolean isInYIntervall(double y)`
Returns if the projection on the Y axis of the line segment covers a certain point on the Y Axis.

### isInXIntervall

`public boolean isInXIntervall(double x)`
Returns if the projection on the X axis of the line segment covers a certain point on the X Axis.

### getXOffset

`public double getXOffset()`
Returns the y value of the line on x coordinate 0.

### getScope

`public double getScope()`
Returns the slope of the line segment.

Returns:
the slope of the line segment.

### length

`public double length()`
Returns the length of the line segment, this is the value of the Euclidean norm.

Returns:
an value > 0.

### getBoundingBox

`public YRectangle getBoundingBox()`
Returns the smallest Rectangle which contains the object.

Specified by:
`getBoundingBox` in interface `PlaneObject`

### intersects

`public boolean intersects(YRectangle box)`
Checks whether the line segment intersects a box.

Parameters:
`box` - A rectangle.
Returns:
`true` if the line segments intersects the box, `false` otherwise.

### contains

`public boolean contains(YPoint point)`
Checks whether a given point lies on this line segment.

Parameters:
`point` - an arbitrary point.
Returns:
`true` if the line segments intersects the box, `false` otherwise.

### intersects

`public boolean intersects(YPoint p)`
Checks whether the line segment intersects a point.

Parameters:
`p` - a point
Returns:
`true` if the line segments intersects the given point, `false` otherwise.

### boxIntersectsSegment

```public static final boolean boxIntersectsSegment(YRectangle box,
YPoint s,
YPoint t)```
Checks whether a line segment intersects a box.

Parameters:
`box` - A rectangle.
`s` - first end point of the line segment.
`t` - second end point of the line segment.
Returns:
`true` if the line segments intersects the box, `false` otherwise.

### boxIntersectsSegment

```public static final boolean boxIntersectsSegment(YRectangle box,
double x1,
double y1,
double x2,
double y2)```
Checks whether a line segment intersects a box. Implemented using the Cohen-Sutherland algorithm.

Parameters:
`box` - A rectangle
`x1` - x-coordinate of the first end point of the line segment
`y1` - y-coordinate of the first end point of the line segment
`x2` - x-coordinate of the second end point of the line segment
`y2` - y-coordinate of the second end point of the line segment
Returns:
`true` if the line segment intersects the box, `false` otherwise.

### boxIntersectsSegment

```public static final 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. Implemented using the Cohen-Sutherland algorithm.

Parameters:
`boxX1` - x-coordinate of the upper left corner of the box
`boxY1` - y-coordinate of the upper left corner of the box
`boxX2` - x-coordinate of the lower right corner of the box
`boxY2` - y-coordinate of the lower right corner of the box
`sX1` - x-coordinate of the first end point of the line segment
`sY1` - y-coordinate of the first end point of the line segment
`sX2` - x-coordinate of the second end point of the line segment
`sY2` - y-coordinate of the second end point of the line segment
Returns:
`true` if the line segment intersects the box, `false` otherwise.

### getIntersection

```public 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.

Parameters:
`s1` - first line segment
`s2` - second line segment

### toYVector

`public YVector toYVector()`
Returns the vector pointing from the first end point to the second end point of the line segment.

### toAffineLine

`public AffineLine toAffineLine()`
Returns the affine line defined by the end points of the line segment.

### getDeltaX

`public double getDeltaX()`
Returns the distance from start to end point in x-coordinates.

Returns:
the distance from start to end point in x-coordinates.

### getDeltaY

`public double getDeltaY()`
Returns the distance from start to end point in y-coordinates.

Returns:
the distance from start to end point in y-coordinates.

### toString

`public java.lang.String toString()`
String representation of the line.

Overrides:
`toString` in class `java.lang.Object`