Package dev.nm.geometry
Class LineSegment
- java.lang.Object
-
- dev.nm.geometry.LineSegment
-
public class LineSegment extends Object
Represent a line segment.
-
-
Constructor Summary
Constructors Constructor Description LineSegment(Point p1, Point p2)
Create a line segment with two given endpoints.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
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)
-
-