org.apache.commons.math3.geometry.euclidean.twod.Line Java Examples

The following examples show how to use org.apache.commons.math3.geometry.euclidean.twod.Line. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #2
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTransform() {

    Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0));
    Transform<Euclidean2D, Euclidean1D> t1 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(0.5 * FastMath.PI,
                        ((Line) t1.apply(l1)).getAngle(),
                        1.0e-10);

    Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0));
    Transform<Euclidean2D, Euclidean1D> t2 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(FastMath.atan2(1.0, -2.0),
                        ((Line) t2.apply(l2)).getAngle(),
                        1.0e-10);

}
 
Example #3
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTransform() throws MathIllegalArgumentException {

    Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0));
    Transform<Euclidean2D, Euclidean1D> t1 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(0.5 * FastMath.PI,
                        ((Line) t1.apply(l1)).getAngle(),
                        1.0e-10);

    Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0));
    Transform<Euclidean2D, Euclidean1D> t2 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(FastMath.atan2(1.0, -2.0),
                        ((Line) t2.apply(l2)).getAngle(),
                        1.0e-10);

}
 
Example #4
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #5
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTransform() throws MathIllegalArgumentException {

    Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0), 1.0e-10);
    Transform<Euclidean2D, Euclidean1D> t1 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(0.5 * FastMath.PI,
                        ((Line) t1.apply(l1)).getAngle(),
                        1.0e-10);

    Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0), 1.0e-10);
    Transform<Euclidean2D, Euclidean1D> t2 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(FastMath.atan2(1.0, -2.0),
                        ((Line) t2.apply(l2)).getAngle(),
                        1.0e-10);

}
 
Example #6
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #7
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #8
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #9
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTransform() throws MathIllegalArgumentException {

    Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0), 1.0e-10);
    Transform<Euclidean2D, Euclidean1D> t1 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(0.5 * FastMath.PI,
                        ((Line) t1.apply(l1)).getAngle(),
                        1.0e-10);

    Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0), 1.0e-10);
    Transform<Euclidean2D, Euclidean1D> t2 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(FastMath.atan2(1.0, -2.0),
                        ((Line) t2.apply(l2)).getAngle(),
                        1.0e-10);

}
 
Example #10
Source File: SegmentTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDistance() {
    Vector2D start = new Vector2D(2, 2);
    Vector2D end = new Vector2D(-2, -2);
    Segment segment = new Segment(start, end, new Line(start, end, 1.0e-10));

    // distance to center of segment
    Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Vector2D(1, -1)), 1.0e-10);

    // distance a point on segment
    Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Vector2D(0, -1)), 1.0e-10);

    // distance to end point
    Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, 4)), 1.0e-10);

    // distance to start point
    Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, -4)), 1.0e-10);
}
 
Example #11
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #12
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2), 1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #13
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAbscissa() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2), 1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D(-3,  4))).getX(),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        (l.toSubSpace(new Vector2D( 3, -4))).getX(),
                        1.0e-10);
    Assert.assertEquals(-5.0,
                        (l.toSubSpace(new Vector2D( 7, -1))).getX(),
                        1.0e-10);
    Assert.assertEquals( 5.0,
                         (l.toSubSpace(new Vector2D(-1, -7))).getX(),
                         1.0e-10);
}
 
Example #14
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testTransform() throws MathIllegalArgumentException {

    Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0));
    Transform<Euclidean2D, Euclidean1D> t1 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(0.5 * FastMath.PI,
                        ((Line) t1.apply(l1)).getAngle(),
                        1.0e-10);

    Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0));
    Transform<Euclidean2D, Euclidean1D> t2 =
        Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
    Assert.assertEquals(FastMath.atan2(1.0, -2.0),
                        ((Line) t2.apply(l2)).getAngle(),
                        1.0e-10);

}
 
Example #15
Source File: SegmentTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDistance() {
    Vector2D start = new Vector2D(2, 2);
    Vector2D end = new Vector2D(-2, -2);
    Segment segment = new Segment(start, end, new Line(start, end, 1.0e-10));

    // distance to center of segment
    Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Vector2D(1, -1)), 1.0e-10);

    // distance a point on segment
    Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Vector2D(0, -1)), 1.0e-10);

    // distance to end point
    Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, 4)), 1.0e-10);

    // distance to start point
    Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, -4)), 1.0e-10);
}
 
Example #16
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkInSegment(Vector2D p,
                               Vector2D p1, Vector2D p2,
                               double tolerance) {
    Line line = new Line(p1, p2);
    if (line.getOffset(p) < tolerance) {
        double x  = (line.toSubSpace(p)).getX();
        double x1 = (line.toSubSpace(p1)).getX();
        double x2 = (line.toSubSpace(p2)).getX();
        return (((x - x1) * (x - x2) <= 0.0)
                || (p1.distance(p) < tolerance)
                || (p2.distance(p) < tolerance));
    } else {
        return false;
    }
}
 
Example #17
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testPointAt() {
    Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
    for (double a = -2.0; a < 2.0; a += 0.2) {
        Vector1D pA = new Vector1D(a);
        Vector2D point = l.toSpace(pA);
        Assert.assertEquals(a, (l.toSubSpace(point)).getX(), 1.0e-10);
        Assert.assertEquals(0.0, l.getOffset(point),   1.0e-10);
        for (double o = -2.0; o < 2.0; o += 0.2) {
            point = l.getPointAt(pA, o);
            Assert.assertEquals(a, (l.toSubSpace(point)).getX(), 1.0e-10);
            Assert.assertEquals(o, l.getOffset(point),   1.0e-10);
        }
    }
}
 
Example #18
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private SubHyperplane<Euclidean2D> buildHalfLine(Vector2D start, Vector2D end,
                                                 boolean startIsVirtual) {
    Line   line  = new Line(start, end);
    double lower = startIsVirtual
    ? Double.NEGATIVE_INFINITY
    : (line.toSubSpace(start)).getX();
    double upper = startIsVirtual
    ? (line.toSubSpace(end)).getX()
    : Double.POSITIVE_INFINITY;
    return new SubLine(line, new IntervalsSet(lower, upper));
}
 
Example #19
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testContains() {
    Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Assert.assertTrue(l.contains(new Vector2D(0, 1)));
    Assert.assertTrue(l.contains(new Vector2D(1, 2)));
    Assert.assertTrue(l.contains(new Vector2D(7, 8)));
    Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
}
 
Example #20
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testContains() {
    Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Assert.assertTrue(l.contains(new Vector2D(0, 1)));
    Assert.assertTrue(l.contains(new Vector2D(1, 2)));
    Assert.assertTrue(l.contains(new Vector2D(7, 8)));
    Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
}
 
Example #21
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testContains() {
    Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Assert.assertTrue(l.contains(new Vector2D(0, 1)));
    Assert.assertTrue(l.contains(new Vector2D(1, 2)));
    Assert.assertTrue(l.contains(new Vector2D(7, 8)));
    Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
}
 
Example #22
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParallel() {
    Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Line l2 = new Line(new Vector2D(2, 2), new Vector2D(3, 3));
    Assert.assertTrue(l1.isParallelTo(l2));
    Line l3 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.5));
    Assert.assertTrue(l1.isParallelTo(l3));
    Line l4 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.51));
    Assert.assertTrue(! l1.isParallelTo(l4));
}
 
Example #23
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParallel() {
    Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Line l2 = new Line(new Vector2D(2, 2), new Vector2D(3, 3));
    Assert.assertTrue(l1.isParallelTo(l2));
    Line l3 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.5));
    Assert.assertTrue(l1.isParallelTo(l3));
    Line l4 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.51));
    Assert.assertTrue(! l1.isParallelTo(l4));
}
 
Example #24
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParallel() {
    Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Line l2 = new Line(new Vector2D(2, 2), new Vector2D(3, 3));
    Assert.assertTrue(l1.isParallelTo(l2));
    Line l3 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.5));
    Assert.assertTrue(l1.isParallelTo(l3));
    Line l4 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.51));
    Assert.assertTrue(! l1.isParallelTo(l4));
}
 
Example #25
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testOriginOffset() {
    Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Assert.assertEquals(FastMath.sqrt(0.5), l1.getOriginOffset(), 1.0e-10);
    Line l2 = new Line(new Vector2D(1, 2), new Vector2D(0, 1));
    Assert.assertEquals(-FastMath.sqrt(0.5), l2.getOriginOffset(), 1.0e-10);
}
 
Example #26
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIntersection() {
    Line    l1 = new Line(new Vector2D( 0, 1), new Vector2D(1, 2));
    Line    l2 = new Line(new Vector2D(-1, 2), new Vector2D(2, 1));
    Vector2D p  = l1.intersection(l2);
    Assert.assertEquals(0.5, p.getX(), 1.0e-10);
    Assert.assertEquals(1.5, p.getY(), 1.0e-10);
}
 
Example #27
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testContains() {
    Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
    Assert.assertTrue(l.contains(new Vector2D(0, 1)));
    Assert.assertTrue(l.contains(new Vector2D(1, 2)));
    Assert.assertTrue(l.contains(new Vector2D(7, 8)));
    Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
}
 
Example #28
Source File: LineTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIntersection() {
    Line    l1 = new Line(new Vector2D( 0, 1), new Vector2D(1, 2), 1.0e-10);
    Line    l2 = new Line(new Vector2D(-1, 2), new Vector2D(2, 1), 1.0e-10);
    Vector2D p  = l1.intersection(l2);
    Assert.assertEquals(0.5, p.getX(), 1.0e-10);
    Assert.assertEquals(1.5, p.getY(), 1.0e-10);
}
 
Example #29
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkInSegment(Vector2D p,
                               Vector2D p1, Vector2D p2,
                               double tolerance) {
    Line line = new Line(p1, p2);
    if (line.getOffset(p) < tolerance) {
        double x  = (line.toSubSpace(p)).getX();
        double x1 = (line.toSubSpace(p1)).getX();
        double x2 = (line.toSubSpace(p2)).getX();
        return (((x - x1) * (x - x2) <= 0.0)
                || (p1.distance(p) < tolerance)
                || (p2.distance(p) < tolerance));
    } else {
        return false;
    }
}
 
Example #30
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private SubHyperplane<Euclidean2D> buildHalfLine(Vector2D start, Vector2D end,
                                                 boolean startIsVirtual) {
    Line   line  = new Line(start, end);
    double lower = startIsVirtual
    ? Double.NEGATIVE_INFINITY
    : (line.toSubSpace(start)).getX();
    double upper = startIsVirtual
    ? (line.toSubSpace(end)).getX()
    : Double.POSITIVE_INFINITY;
    return new SubLine(line, new IntervalsSet(lower, upper));
}