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

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

Introduction

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

Prototype

public Vector2D intersection(final Line other) 

Source Link

Document

Get the intersection point of the instance and another line.

Usage

From source file:eu.mihosoft.vrl.workflow.fx.MathTest.java

public static void main(String[] args) {
    Vector2D p1 = new Vector2D(-1, 0);
    Vector2D p2 = new Vector2D(1, 0);

    Vector2D p3 = new Vector2D(0, -1);
    Vector2D p4 = new Vector2D(0, 1);

    Line l1 = new Line(p1, p2, 1e-5);

    Line l2 = new Line(p3, p4, 1e-5);

    Segment s1 = new Segment(p2, p1, l1);
    Segment s2 = new Segment(p4, p3, l2);

    Vector2D lIntersection = l1.intersection(l2);
    Vector2D sIntersection = new SubLine(s1).intersection(new SubLine(s2), true);

    System.out.println("l-intersection: " + lIntersection);
    System.out.println("s-intersection: " + sIntersection);

}

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.
 * /*  w  w  w  .j  av a2s  . c  o  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;
}