/** * Calculates the slope value of this line. * <p> * The slope 's' can be used to calculate the y-coordinate of a point located on the line given its * x-coordinate:<br> * y = s * x + y<sub>0</sub><br> * where y<sub>0</sub> is the y-coordinate at which this line intercepts the y-axis and which can be * obtained with {@link #yIntercept()}. * </p> * * @return the value of the slope of this line. */ default double slope() { if (getDirectionX() == 0.0 && getDirectionY() > 0.0) { return Double.POSITIVE_INFINITY; } if (getDirectionX() == 0.0 && getDirectionY() < 0.0) { return Double.NEGATIVE_INFINITY; } return getDirectionY() / getDirectionX(); }
/** * The x-coordinate at which this line intercept the x-axis, i.e. the line defined by {@code y=0}. * * @return the x-coordinate of the intersection between this line and the x-axis. */ default double xIntercept() { double parameterAtIntercept = -getPointY() / getDirectionY(); return parameterAtIntercept * getDirectionX() + getPointX(); }
/** * The y-coordinate at which this line intercept the y-axis, i.e. the line defined by {@code x=0}. * * @return the y-coordinate of the intersection between this line and the y-axis. */ default double yIntercept() { double parameterAtIntercept = -getPointX() / getDirectionX(); return parameterAtIntercept * getDirectionY() + getPointY(); }
double pointOnBisectorX = t * getDirectionX() + getPointX(); double pointOnBisectorY = t * getDirectionY() + getPointY(); double bisectorDirectionX = getDirectionX() + secondLine.getDirectionX(); double bisectorDirectionY = getDirectionY() + secondLine.getDirectionY(); interiorBisectorToPack.set(pointOnBisectorX, pointOnBisectorY, bisectorDirectionX, bisectorDirectionY);
double x1 = x0 + getDirectionX(); double y1 = y0 + getDirectionY(); return EuclidGeometryTools.percentageAlongLineSegment2D(pointOnLine.getX(), pointOnLine.getY(), x0, y0, x1, y1);
/** * Checks if a line intersects the edge with the given index. */ public static boolean doesLineIntersectEdge(Line2DReadOnly line, int edgeIndex, ConvexPolygon2DReadOnly polygon) { if (polygon.getNumberOfVertices() < 2) return false; Point2DReadOnly edgeStart = polygon.getVertex(edgeIndex); Point2DReadOnly edgeEnd = polygon.getNextVertex(edgeIndex); double lineDirectionX = line.getDirectionX(); double lineDirectionY = line.getDirectionY(); double edgeDirectionX = edgeEnd.getX() - edgeStart.getX(); double edgeDirectionY = edgeEnd.getY() - edgeStart.getY(); if (EuclidGeometryTools.areVector2DsParallel(lineDirectionX, lineDirectionY, edgeDirectionX, edgeDirectionY, EuclidGeometryTools.ONE_TEN_MILLIONTH)) return false; else return EuclidGeometryTools.doLine2DAndLineSegment2DIntersect(line.getPoint(), line.getDirection(), edgeStart, edgeEnd); }