Class JavaLine2D

    • 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 point
        y1 - y-coordinate of start point
        x2 - x-coordinate of end point
        y2 - y-coordinate of end point
      • JavaLine2D

        public JavaLine2D​(double x1,
                          double y1,
                          double x2,
                          double y2)
    • Method Detail

      • getIntersectionPoint

        public static JavaPoint2D getIntersectionPoint​(JavaLine2D line1,
                                                       JavaLine2D line2)
        http://stackoverflow.com/a/19342455
        Parameters:
        line1 - line 1
        line2 - 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 line
        rotation - The getRotation of the line
        stepWidth - 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 lines

        Calculation of cut angle: https://de.wikipedia.org/wiki/Schnittwinkel_(Geometrie)

        Parameters:
        line1 - the first line
        line2 - 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 point
        rotation - the getRotation in radians
        length - the length of the line
        Returns:
        the resulting java line
        See Also:
        https://stackoverflow.com/a/14842362
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isPointOnLine

        public boolean isPointOnLine​(JavaPoint2D point,
                                     double epsilon)
        Method which checks if a point is on a line or not
        Parameters:
        point - to be checked
        epsilon - 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.
      • 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 single JavaLine2D 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 single JavaLine2D into multiple parts at the given split points
        Parameters:
        splitPoints - points where to split the JavaLine2D
        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 class AbstractJavaLine<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 rotate
        rotationCenter - Point to rotate the line around
        Returns:
        new object that represents this line rotated around the given rotationCenter