# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.geometry

## Class LineSegment

• public class LineSegment
extends Object
Represent a line segment.
• ### Constructor Summary

Constructors
Constructor and Description
LineSegment(Point p1, Point p2)
Create a line segment with two given endpoints.
• ### Method Summary

All Methods
Modifier and Type Method and Description
int dimension()
Get the dimension of the coordinate space.
double distance(Point p)
Calculate the shortest distance between a point and this line segment in Euclidean geometry.
Point getEndPoint1()
Get the first endpoint.
Point getEndPoint2()
Get the second endpoint.
double length()
Get the length of the line segment.
double perpendicularDistance(Point p)
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### LineSegment

public LineSegment(Point p1,
Point p2)
Create a line segment with two given endpoints.
Parameters:
p1 - the first endpoint
p2 - the second endpoint
• ### Method Detail

• #### getEndPoint1

public Point getEndPoint1()
Get the first endpoint.
Returns:
the first endpoint
• #### getEndPoint2

public Point getEndPoint2()
Get the second endpoint.
Returns:
the second endpoint
• #### dimension

public int dimension()
Get the dimension of the coordinate space.
Returns:
the dimension of the coordinate space
• #### length

public double length()
Get the length of the line segment.
Returns:
the line length
• #### distance

public double distance(Point p)
Calculate the shortest distance between a point and this line segment in Euclidean geometry. If the projection of the point on the line is outside of the segment, the distance between the point and the closest endpoint of the line segment is returned.
Parameters:
p - the point
Returns:
the distance
• #### perpendicularDistance

public double perpendicularDistance(Point p)