public class Line2d extends Object implements GeometricObject, Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
Line2d.IntersectionResult
The result of a line intersection.
|
static class |
Line2d.IntersectionType
The type of a result of a line intersection
|
Modifier and Type | Field and Description |
---|---|
Point2d |
begin
Start point of line
|
Point2d |
end
End point of line
|
Constructor and Description |
---|
Line2d()
Construct a line
|
Line2d(float x1,
float y1,
float x2,
float y2)
Construct a line
|
Line2d(Point2d begin,
Point2d end)
Construct a line
|
Modifier and Type | Method and Description |
---|---|
Point2d |
calculateCentroid()
Calculate the centroid of the shape
|
double |
calculateHorizontalAngle()
Returns the angle (radians) this line makes with a horizontal line
|
double |
calculateLength() |
Rectangle |
calculateRegularBoundingBox()
Compute the regular (oriented to the axes) bounding box of the shape.
|
double |
calculateVerticalAngle()
Returns the angle (radians) this line makes with a vertical line
|
Line2d |
clone() |
static double |
distance(float p1x,
float p1y,
float p2x,
float p2y)
Get the Euclidean distance between two points
|
static double |
distance(Point2d p1,
Point2d p2)
Get the Euclidean distance between two points
|
boolean |
equals(Object other) |
Point2d |
getBeginPoint()
Get the start point
|
Point2d |
getEndPoint()
Get the end point
|
double |
getHeight() |
Line2d.IntersectionResult |
getIntersection(Line2d otherLine)
Calculates the intersection point of this line and another line
|
Line2d |
getNormal()
Returns a line that is at 90 degrees to the original line.
|
Line2d |
getNormal(Point2d p)
Returns a line that is at 90 degrees to the original line and also
passes through the given point.
|
double |
getWidth() |
int |
hashCode() |
boolean |
isInLine(Point2d p,
float tolerance)
Tests whether the given point lies on this line.
|
boolean |
isOnLine(Point2d p,
float tolerance)
Tests whether the given point lies on this line.
|
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.
|
Line2d |
lineWithinSquare(Rectangle r)
Given a rectangle, return the line that actually fits inside the rectangle for this line
|
double |
maxX() |
double |
maxY() |
double |
minX() |
double |
minY() |
Point2d |
reflectAroundLine(Point2d pointToReflect)
Reflects a point around a this line.
|
void |
scale(float sc)
Scale the shape by the given amount about (0,0).
|
void |
scale(Point2d centre,
float sc)
Scale the shape by the given amount about the given point.
|
void |
scaleCentroid(float sc)
Scale the shape about its centroid.
|
void |
setBeginPoint(Point2d begin)
Set the start point
|
Point2d |
setEndPoint()
Get the end point
|
void |
setEndPoint(Point2d end)
Set the end point
|
String |
toString() |
Point2dImpl |
toUnitVector()
Convert the line to a unit vector
|
Line2d |
transform(Jama.Matrix transform)
Transform a line.
|
void |
translate(float x,
float y)
Translate the shapes position
|
public Line2d()
public Line2d(Point2d begin, Point2d end)
begin
- start pointend
- end pointpublic Line2d(float x1, float y1, float x2, float y2)
x1
- x-ordinate of start pointy1
- y-ordinate of start pointx2
- x-ordinate of end pointy2
- y-ordinate of end pointpublic void setBeginPoint(Point2d begin)
begin
- start pointpublic void setEndPoint(Point2d end)
end
- end pointpublic Point2d getBeginPoint()
public Point2d getEndPoint()
public Point2d setEndPoint()
public Line2d.IntersectionResult getIntersection(Line2d otherLine)
otherLine
- The other line segmentLine2d.IntersectionResult
public Point2d reflectAroundLine(Point2d pointToReflect)
pointToReflect
- The point to reflectpublic Line2d lineWithinSquare(Rectangle r)
r
- the boundspublic static double distance(Point2d p1, Point2d p2)
p1
- the first pointp2
- the second pointpublic static double distance(float p1x, float p1y, float p2x, float p2y)
p1x
- the first pointp1y
- the first pointp2x
- the second pointp2y
- the first pointpublic static Line2d lineFromRotation(int x1, int y1, double theta, int length)
x1
- x-ordinate of starting pointy1
- y-ordinate of starting pointtheta
- angle in radianslength
- line lengthpublic double calculateLength()
public double calculateHorizontalAngle()
public double calculateVerticalAngle()
public Line2d transform(Jama.Matrix transform)
transform
in interface GeometricObject
transform
- the transform matrix.public Line2d getNormal()
public Line2d getNormal(Point2d p)
p
- A point that must exist on the normal linepublic void translate(float x, float y)
GeometricObject
translate
in interface GeometricObject
x
- x-translationy
- y-translationpublic boolean isOnLine(Point2d p, float tolerance)
p
- The point to test.tolerance
- The tolerance to use in the testpublic boolean isInLine(Point2d p, float tolerance)
p
- The point to test.tolerance
- The tolerance to use in the testpublic Rectangle calculateRegularBoundingBox()
GeometricObject
calculateRegularBoundingBox
in interface GeometricObject
public void scale(float sc)
GeometricObject
scale
in interface GeometricObject
sc
- the scale factor.public void scale(Point2d centre, float sc)
GeometricObject
scale
in interface GeometricObject
centre
- the centre of the scaling operationsc
- the scale factorpublic void scaleCentroid(float sc)
GeometricObject
scaleCentroid
in interface GeometricObject
sc
- the scale factorpublic Point2d calculateCentroid()
GeometricObject
calculateCentroid
in interface GeometricObject
public double minX()
minX
in interface GeometricObject
public double minY()
minY
in interface GeometricObject
public double maxX()
maxX
in interface GeometricObject
public double maxY()
maxY
in interface GeometricObject
public double getWidth()
getWidth
in interface GeometricObject
public double getHeight()
getHeight
in interface GeometricObject
public Point2dImpl toUnitVector()