Example usage for org.apache.commons.math3.geometry.euclidean.twod Line Line

List of usage examples for org.apache.commons.math3.geometry.euclidean.twod Line Line

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.twod Line Line.

Prototype

public Line(final Vector2D p, final double angle) 

Source Link

Document

Build a line from a point and an angle.

Usage

From source file:edu.stanford.cfuller.imageanalysistools.util.VoronoiDiagram.java

protected Hyperplane<Euclidean2D> constructBisectingHyperplane(Vector2D firstPoint, Vector2D secondPoint) {

    Vector2D middlePoint = firstPoint.add(secondPoint).scalarMultiply(0.5);
    Vector2D difference = secondPoint.subtract(firstPoint);

    double angle = Math.atan2(difference.getY(), difference.getX());

    angle -= Math.PI / 2.0; // rotate 90 degrees

    Line bisector = new Line(middlePoint, angle);

    return bisector;

}

From source file:uk.ac.ebi.cysbgn.methods.SegmentMethods.java

public static Vector2D pointOutNodeBoundary(Rectangle2D.Double nodeRectangle, Vector2D start, Vector2D end,
        double distance) {
    // C = A - k ( A - B )
    // k = distance / distance_From_A_to_B

    Line arcLine = new Line(start, end);

    // Calculate the point here the arc intersects the node boundary rectangle
    Vector2D boundaryPoint = nodeArcIntersectionPoint(nodeRectangle, arcLine);

    Double k = distance / boundaryPoint.distance(end);

    Double Xc = boundaryPoint.getX() - k * (boundaryPoint.getX() - end.getX());
    Double Xy = boundaryPoint.getY() - k * (boundaryPoint.getY() - end.getY());

    return new Vector2D(Xc, Xy);
}

From source file:uk.ac.ebi.cysbgn.methods.SegmentMethods.java

/**
 * IMPORTANT: the y axis is inverted since the origin of the axis in Cytoscape
 * is located in the top left corner of the screen.
 * //from   w ww  . j a v a2s  .co m
 * @param nodeRectangle
 * @param arcLine
 * @return
 */
public static Vector2D nodeArcIntersectionPoint(Rectangle2D.Double nodeRectangle, Line arcLine) {

    Line topLine = new Line(new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMinY()),
            new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMinY()));

    Line bottomLine = new Line(new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMaxY()),
            new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMaxY()));

    Line leftLine = new Line(new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMinY()),
            new Vector2D(nodeRectangle.getMinX(), nodeRectangle.getMaxY()));

    Line rightLine = new Line(new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMinY()),
            new Vector2D(nodeRectangle.getMaxX(), nodeRectangle.getMaxY()));

    Vector2D topLineIntersection = topLine.intersection(arcLine);
    if (topLineIntersection != null)
        return topLineIntersection;

    Vector2D bottomLineIntersection = bottomLine.intersection(arcLine);
    if (bottomLineIntersection != null)
        return bottomLineIntersection;

    Vector2D leftLineIntersection = leftLine.intersection(arcLine);
    if (leftLineIntersection != null)
        return leftLineIntersection;

    Vector2D rightLineIntersection = rightLine.intersection(arcLine);
    if (rightLineIntersection != null)
        return rightLineIntersection;

    return null;
}