public class MTBLineSegment2D extends Line2D.Double
This class adds some useful functions to Line2D.Double
,
mostly concerning geometrical calculations like intersections, orientations,
scalar products and distances.
For consistency with ImageJ each segment also has a specific width. By
default the width of a segment is 1.
Line2D.Double
,
Line
,
Serialized FormLine2D.Double, Line2D.Float
Modifier and Type | Field and Description |
---|---|
private double |
width
Width of the segment (for compatibility with ImageJ).
|
x1, x2, y1, y2
Constructor and Description |
---|
MTBLineSegment2D(double X1,
double Y1,
double X2,
double Y2)
Constructor.
|
MTBLineSegment2D(MTBLineSegment2D line)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
MTBLineSegment2D |
clone() |
boolean |
containsPoint(double px,
double py)
Checks if a given point is part of the segment.
|
Point2D.Double |
getIntersection(MTBLineSegment2D ls)
Calculates the point of intersection between the segments.
|
double |
getNorm()
Calculates the Euclidean norm of the segment.
|
double |
getOrientation(double px,
double py)
Deprecated.
|
LinkedList<Point2D.Double> |
getPixelsAlongSegment()
Calculates the set of integer pixel positions along the a segment.
|
double |
getPointDist(double x,
double y)
Deprecated.
|
double |
getWidth()
Get the width associated with the segment.
|
double |
scalprod(MTBLineSegment2D ls)
Calculates the scalar product of the given segment to this one.
|
void |
setWidth(double w)
Set the width associated with the segment.
|
getBounds2D, getP1, getP2, getX1, getX2, getY1, getY2, setLine
contains, contains, contains, contains, getBounds, getPathIterator, getPathIterator, intersects, intersects, intersectsLine, intersectsLine, linesIntersect, ptLineDist, ptLineDist, ptLineDist, ptLineDistSq, ptLineDistSq, ptLineDistSq, ptSegDist, ptSegDist, ptSegDist, ptSegDistSq, ptSegDistSq, ptSegDistSq, relativeCCW, relativeCCW, relativeCCW, setLine, setLine
public MTBLineSegment2D(double X1, double Y1, double X2, double Y2)
X1
- x-coordinate of first point.Y1
- y-coordinate of first point.X2
- x-coordinate of second point.Y2
- y-coordinate of second point.public MTBLineSegment2D(MTBLineSegment2D line)
line
- Line segment to copy.public MTBLineSegment2D clone()
public void setWidth(double w)
w
- Width of segment.public double getWidth()
public double scalprod(MTBLineSegment2D ls)
The segments are interpreted as vectors, directed from the first point of the segment to the second.
ls
- Input line segment.public double getNorm()
public boolean containsPoint(double px, double py)
px
- x-coordinate of the point.py
- y-coordinate of the point.@Deprecated public double getPointDist(double x, double y)
@Deprecated public double getOrientation(double px, double py)
If return value is positive, point lies left of the segment, if it is negative, the point is located on the right. If the return value is zero, the point is located on the segment or at least on the line to which the segment belongs to.
px
- x-coordinate of the point.py
- y-coordinate of the point.public Point2D.Double getIntersection(MTBLineSegment2D ls)
ls
- Line segment to be checked.public LinkedList<Point2D.Double> getPixelsAlongSegment()
This method is based on the Bresenham algorithm for rendering line segments. Code was 'stolen' from Wikipedia, and then translated into Java (German comments where kept).
Copyright © 2010–2020 Martin Luther University Halle-Wittenberg, Institute of Computer Science, Pattern Recognition and Bioinformatics. All rights reserved.