org.openimaj.math.geometry.line

Class Line2d

• Field Detail

• end

public Point2d end
End point of line
• Constructor Detail

• Line2d

public Line2d()
Construct a line
• Line2d

public Line2d(Point2d begin,
Point2d end)
Construct a line
Parameters:
begin - start point
end - end point
• Line2d

public Line2d(float x1,
float y1,
float x2,
float y2)
Construct a line
Parameters:
x1 - x-ordinate of start point
y1 - y-ordinate of start point
x2 - x-ordinate of end point
y2 - y-ordinate of end point
• Method Detail

• setBeginPoint

public void setBeginPoint(Point2d begin)
Set the start point
Parameters:
begin - start point
• setEndPoint

public void setEndPoint(Point2d end)
Set the end point
Parameters:
end - end point
• getBeginPoint

public Point2d getBeginPoint()
Get the start point
Returns:
the start point
• getEndPoint

public Point2d getEndPoint()
Get the end point
Returns:
The end point
• setEndPoint

public Point2d setEndPoint()
Get the end point
Returns:
the end point
• reflectAroundLine

public Point2d reflectAroundLine(Point2d pointToReflect)
Reflects a point around a this line.
Parameters:
pointToReflect - The point to reflect
Returns:
The reflected point
• lineWithinSquare

public Line2d lineWithinSquare(Rectangle r)
Given a rectangle, return the line that actually fits inside the rectangle for this line
Parameters:
r - the bounds
Returns:
the line
• distance

public static double distance(Point2d p1,
Point2d p2)
Get the Euclidean distance between two points
Parameters:
p1 - the first point
p2 - the second point
Returns:
the distance
• distance

public static double distance(float p1x,
float p1y,
float p2x,
float p2y)
Get the Euclidean distance between two points
Parameters:
p1x - the first point
p1y - the first point
p2x - the second point
p2y - the first point
Returns:
the distance
• lineFromRotation

public static Line2d lineFromRotation(int x1,
int y1,
double theta,
int length)
Create a line of a given length that starts at a point and has a given angle.
Parameters:
x1 - x-ordinate of starting point
y1 - y-ordinate of starting point
length - line length
Returns:
the line
• calculateLength

public double calculateLength()
Description copied from interface: Path2d
Calculate the length of the path
Specified by:
calculateLength in interface Path2d
Returns:
The length of the line.
• calculateHorizontalAngle

public double calculateHorizontalAngle()
Returns the angle (radians) this line makes with a horizontal line
Returns:
the angle this line makes with a horizontal line
• calculateVerticalAngle

public double calculateVerticalAngle()
Returns the angle (radians) this line makes with a vertical line
Returns:
the angle this line makes with a vertical line
• transform

public Line2d transform(Jama.Matrix transform)
Transform a line.
Specified by:
transform in interface GeometricObject2d
Parameters:
transform - the transform matrix.
Returns:
the transformed line.
• getNormal

public Line2d getNormal()
Returns a line that is at 90 degrees to the original line.
Returns:
the normal line
• getNormal

public Line2d getNormal(Point2d p)
Returns a line that is at 90 degrees to the original line and also passes through the given point.
Parameters:
p - A point that must exist on the normal line
Returns:
a new line at right-angles to this
• isInLine

public boolean isInLine(Point2d p,
float tolerance)
Tests whether the given point lies on this line. If the point sits on the line but is outside of the end points, then this function will return false.
Parameters:
p - The point to test.
tolerance - The tolerance to use in the test
Returns:
TRUE if the point lies on this line.
• scale

public void scale(float sc)
Description copied from interface: GeometricObject2d
Scale the shape by the given amount about (0,0). Scalefactors between 0 and 1 shrink the shape.
Specified by:
scale in interface GeometricObject2d
Parameters:
sc - the scale factor.
• scale

public void scale(Point2d centre,
float sc)
Description copied from interface: GeometricObject2d
Scale the shape by the given amount about the given point. Scalefactors between 0 and 1 shrink the shape.
Specified by:
scale in interface GeometricObject2d
Parameters:
centre - the centre of the scaling operation
sc - the scale factor
• toUnitVector

public Point2dImpl toUnitVector()
Convert the line to a unit vector
Returns:
unit vector in the same direction as the line
• begin

public Point2d begin()
Description copied from interface: Path2d
Get the beginning of the path
Specified by:
begin in interface Path2d
Returns:
the beginning
• end

public Point2d end()
Description copied from interface: Path2d
Get the end of the path
Specified by:
end in interface Path2d
Returns:
the end
• asPolyline

public Polyline asPolyline()
Description copied from interface: Path2d
Convert the path to a polyline representation
Specified by:
asPolyline in interface Path2d
Returns:
a polyline representation of the path
• lineIterator

public Iterator<Line2dlineIterator()
Description copied from interface: Path2d
Convert the path to a iterated polyline representation
Specified by:
lineIterator in interface Path2d
Returns:
an iterated polyline representation of the path
• isOnLine

public boolean isOnLine(Point2d p,
float tolerance)
Tests whether the given point lies on this line. Note that this will test whether the point sits on a line that travels to infinity in both directions.
Parameters:
p - The point to test.
tolerance - The tolerance to use in the test
Returns:
TRUE if the point lies on this line.
• distanceToLine

public float distanceToLine(Point2d p)
Returns the shortest distance between the point and this line. Note that this assumes the line travels to infinity in both directions.
Parameters:
p - The point to test.
Returns:
The distance from the point to the closest point on the line