Class JavaLine2D
- java.lang.Object
-
- science.aist.imaging.api.domain.AbstractJavaLine<JavaPoint2D>
-
- science.aist.imaging.api.domain.twodimensional.JavaLine2D
-
- All Implemented Interfaces:
Serializable
public class JavaLine2D extends AbstractJavaLine<JavaPoint2D> implements Serializable
Representation of a Line
- Since:
- 1.0
- Author:
- Andreas Pointner
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class science.aist.imaging.api.domain.AbstractJavaLine
endPoint, startPoint
-
-
Constructor Summary
Constructors Constructor Description JavaLine2D(double x1, double y1, double x2, double y2)
JavaLine2D(int x1, int y1, int x2, int y2)
set line by coordinates of the start and end pointJavaLine2D(JavaPoint2D startPoint, JavaPoint2D endpoint)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<JavaPoint2D>
calculateBresenham()
https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#Cprotected JavaPoint2D
calculateCenterPoint()
Calculate the center point of a given line x = (start.x + end.x) / 2 y = (start.y + end.y) / 2protected double
calculateGradient()
Calculates the gradient of the lineprotected double
calculateRotation()
Returns the getRotation of the given line.JavaPolygon2D
calculateSquareAroundLine(double distance)
This function calculates a square around a line with a given distance.static JavaLine2D
createByCenterRotationAndLength(JavaPoint2D center, double rotation, double length)
Create a Java Line by using the center of the line + a given getRotation + the length of the linestatic JavaLine2D
createLine(JavaPoint2D point, double rotation, int stepWidth)
Create a line out of a point and a specific getRotation with the "length" stepWidthstatic double
cutAngle(JavaLine2D line1, JavaLine2D line2)
Calculates the cut angle between two linesboolean
equals(Object o)
static JavaPoint2D
getIntersectionPoint(JavaLine2D line1, JavaLine2D line2)
http://stackoverflow.com/a/19342455JavaPoint2D
getLineDirection()
JavaPoint2D
getPointAlongLine(double distance)
Method for getting a point along this line with the given distance from the startPoint * (Based on https://math.stackexchange.com/questions/175896/finding-a-point-along-a-line-a-certain-distance-away-from-another-point)int
hashCode()
boolean
isPointOnLine(JavaPoint2D point)
Method which checks if a point is on a line or notboolean
isPointOnLine(JavaPoint2D point, double epsilon)
Method which checks if a point is on a line or notJavaLine2D
move(double distance)
Moves a line perpendicularJavaLine2D
rotate(double angle)
Rotates this line around its mid pointJavaLine2D
rotate(double angle, JavaPoint2D rotationCenter)
Rotates this line around the given rotationCenterOptional<science.aist.jack.data.Pair<JavaLine2D,JavaLine2D>>
split(JavaPoint2D splitPoint)
Method which splits the singleJavaLine2D
into two parts at the given split pointSet<JavaLine2D>
split(JavaPoint2D... splitPoints)
Splits the singleJavaLine2D
into multiple parts at the given split points-
Methods inherited from class science.aist.imaging.api.domain.AbstractJavaLine
getInterpolatedPoints, getInterpolatedPoints, length
-
-
-
-
Constructor Detail
-
JavaLine2D
public JavaLine2D(int x1, int y1, int x2, int y2)
set line by coordinates of the start and end point- Parameters:
x1
- x-coordinate of start pointy1
- y-coordinate of start pointx2
- x-coordinate of end pointy2
- y-coordinate of end point
-
JavaLine2D
public JavaLine2D(double x1, double y1, double x2, double y2)
-
JavaLine2D
public JavaLine2D(JavaPoint2D startPoint, JavaPoint2D endpoint)
-
-
Method Detail
-
getIntersectionPoint
public static JavaPoint2D getIntersectionPoint(JavaLine2D line1, JavaLine2D line2)
http://stackoverflow.com/a/19342455- Parameters:
line1
- line 1line2
- line 2- Returns:
- the point where the two lines intersect or null if there is no intersection
-
createLine
public static JavaLine2D createLine(JavaPoint2D point, double rotation, int stepWidth)
Create a line out of a point and a specific getRotation with the "length" stepWidth- Parameters:
point
- The center point of the linerotation
- The getRotation of the linestepWidth
- the step width (line length)- Returns:
- a new line object
-
cutAngle
public static double cutAngle(JavaLine2D line1, JavaLine2D line2)
Calculates the cut angle between two linesCalculation of cut angle: https://de.wikipedia.org/wiki/Schnittwinkel_(Geometrie)
- Parameters:
line1
- the first lineline2
- the second line- Returns:
- the cut angle between the lines in rad
-
createByCenterRotationAndLength
public static JavaLine2D createByCenterRotationAndLength(JavaPoint2D center, double rotation, double length)
Create a Java Line by using the center of the line + a given getRotation + the length of the line
- Parameters:
center
- the center pointrotation
- the getRotation in radianslength
- the length of the line- Returns:
- the resulting java line
- See Also:
- https://stackoverflow.com/a/14842362
-
getLineDirection
public JavaPoint2D getLineDirection()
- Overrides:
getLineDirection
in classAbstractJavaLine<JavaPoint2D>
- Returns:
- The direction vector of this line
-
isPointOnLine
public boolean isPointOnLine(JavaPoint2D point, double epsilon)
Method which checks if a point is on a line or not- Parameters:
point
- to be checkedepsilon
- needed to check if cross product is greater than some epsilon- Returns:
- true iff point is on line, else false
- See Also:
- Stackoverflow
-
isPointOnLine
public boolean isPointOnLine(JavaPoint2D point)
Method which checks if a point is on a line or not- Parameters:
point
- to be checked- Returns:
- true iff point is on line, else false
- See Also:
- Stackoverflow
-
calculateRotation
protected double calculateRotation()
Returns the getRotation of the given line. This function returns 0 degree in case start.y = end.y And PI/2 in case of start.x = end.x The result is in the range between 0 and 2 PI. (Be aware of that, some implementation return from -PI to PI) The getRotation of a line usually only makes sense between 0 and PI because its symmetric, but we assume, that a line goes the other direction if start and end point are reversed.- Returns:
- getRotation of the line in radians.
-
calculateCenterPoint
protected JavaPoint2D calculateCenterPoint()
Calculate the center point of a given line x = (start.x + end.x) / 2 y = (start.y + end.y) / 2- Specified by:
calculateCenterPoint
in classAbstractJavaLine<JavaPoint2D>
- Returns:
- center point of the line
-
calculateSquareAroundLine
public JavaPolygon2D calculateSquareAroundLine(double distance)
This function calculates a square around a line with a given distance.- Parameters:
distance
- distance- Returns:
- four corner points of the Square around
-
calculateGradient
protected double calculateGradient()
Calculates the gradient of the line- Returns:
- calculates the gradient of the line if StartPoint.x == EndPoint.x --> Double.VALUE is the result.
-
move
public JavaLine2D move(double distance)
Moves a line perpendicular- Parameters:
distance
- the distance how far the line should be moved- Returns:
- the moved new line
-
split
public Optional<science.aist.jack.data.Pair<JavaLine2D,JavaLine2D>> split(JavaPoint2D splitPoint)
Method which splits the singleJavaLine2D
into two parts at the given split point- Parameters:
splitPoint
- position where to cut the line- Returns:
- a pair of
JavaLine2D
representing the two, split parts of the original line; Optional is empty iff splitPoint is not on the JavaLine
-
split
public Set<JavaLine2D> split(JavaPoint2D... splitPoints)
Splits the singleJavaLine2D
into multiple parts at the given split points- Parameters:
splitPoints
- points where to split theJavaLine2D
- Returns:
- Collection of all splits, which is empty if line could not be split at any point
-
calculateBresenham
protected List<JavaPoint2D> calculateBresenham()
https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C- Returns:
- list of points.
-
getPointAlongLine
public JavaPoint2D getPointAlongLine(double distance)
Method for getting a point along this line with the given distance from the startPoint * (Based on https://math.stackexchange.com/questions/175896/finding-a-point-along-a-line-a-certain-distance-away-from-another-point)- Specified by:
getPointAlongLine
in classAbstractJavaLine<JavaPoint2D>
- Parameters:
distance
- from the startPoint- Returns:
- the point with the given distance
-
rotate
public JavaLine2D rotate(double angle)
Rotates this line around its mid point- Parameters:
angle
- angle (in degrees) to rotate- Returns:
- new object that represents this line rotated around its midpoint
-
rotate
public JavaLine2D rotate(double angle, JavaPoint2D rotationCenter)
Rotates this line around the given rotationCenter- Parameters:
angle
- angle (in radian) to rotaterotationCenter
- Point to rotate the line around- Returns:
- new object that represents this line rotated around the given rotationCenter
-
-