Package org.apache.commons.math3.geometry.euclidean.twod

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


        while (hull.size() >= 2) {
            final int size = hull.size();
            final Vector2D p1 = hull.get(size - 2);
            final Vector2D p2 = hull.get(size - 1);

            final double offset = new Line(p1, p2, tolerance).getOffset(point);
            if (FastMath.abs(offset) < tolerance) {
                // the point is collinear to the line (p1, p2)

                final double distanceToCurrent = p1.distance(point);
                if (distanceToCurrent < tolerance || p2.distance(point) < tolerance) {
View Full Code Here


                this.lineSegments = new Segment[0];
            } else if (size == 2) {
                this.lineSegments = new Segment[1];
                final Vector2D p1 = vertices[0];
                final Vector2D p2 = vertices[1];
                this.lineSegments[0] = new Segment(p1, p2, new Line(p1, p2, tolerance));
            } else {
                this.lineSegments = new Segment[size];
                Vector2D firstPoint = null;
                Vector2D lastPoint = null;
                int index = 0;
                for (Vector2D point : vertices) {
                    if (lastPoint == null) {
                        firstPoint = point;
                        lastPoint = point;
                    } else {
                        this.lineSegments[index++] =
                                new Segment(lastPoint, point, new Line(lastPoint, point, tolerance));
                        lastPoint = point;
                    }
                }
                this.lineSegments[index] =
                        new Segment(lastPoint, firstPoint, new Line(lastPoint, firstPoint, tolerance));
            }
        }
        return lineSegments;
    }
View Full Code Here

        while (hull.size() >= 2) {
            final int size = hull.size();
            final Vector2D p1 = hull.get(size - 2);
            final Vector2D p2 = hull.get(size - 1);

            final double offset = new Line(p1, p2, tolerance).getOffset(point);
            if (FastMath.abs(offset) < tolerance) {
                // the point is collinear to the line (p1, p2)

                final double distanceToCurrent = p1.distance(point);
                if (distanceToCurrent < tolerance || p2.distance(point) < tolerance) {
View Full Code Here

                this.lineSegments = new Segment[0];
            } else if (size == 2) {
                this.lineSegments = new Segment[1];
                final Vector2D p1 = vertices[0];
                final Vector2D p2 = vertices[1];
                this.lineSegments[0] = new Segment(p1, p2, new Line(p1, p2, tolerance));
            } else {
                this.lineSegments = new Segment[size];
                Vector2D firstPoint = null;
                Vector2D lastPoint = null;
                int index = 0;
                for (Vector2D point : vertices) {
                    if (lastPoint == null) {
                        firstPoint = point;
                        lastPoint = point;
                    } else {
                        this.lineSegments[index++] =
                                new Segment(lastPoint, point, new Line(lastPoint, point, tolerance));
                        lastPoint = point;
                    }
                }
                this.lineSegments[index] =
                        new Segment(lastPoint, firstPoint, new Line(lastPoint, firstPoint, tolerance));
            }
        }
        return lineSegments;
    }
View Full Code Here

    @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
View Full Code Here

public class LineTest {

    @Test
    public void testContains() {
        Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2), 1.0e-10);
        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)));
    }
View Full Code Here

        Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
    }

    @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(-34))).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);
    }
View Full Code Here

                             1.0e-10);
    }

    @Test
    public void testOffset() {
        Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2), 1.0e-10);
        Assert.assertEquals(-5.0, l.getOffset(new Vector2D(5, -3)), 1.0e-10);
        Assert.assertEquals(+5.0, l.getOffset(new Vector2D(-5, 2)), 1.0e-10);
    }
View Full Code Here

        Assert.assertEquals(+5.0, l.getOffset(new Vector2D(-5, 2)), 1.0e-10);
    }

    @Test
    public void testDistance() {
        Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2), 1.0e-10);
        Assert.assertEquals(+5.0, l.distance(new Vector2D(5, -3)), 1.0e-10);
        Assert.assertEquals(+5.0, l.distance(new Vector2D(-5, 2)), 1.0e-10);
    }
View Full Code Here

        Assert.assertEquals(+5.0, l.distance(new Vector2D(-5, 2)), 1.0e-10);
    }

    @Test
    public void testPointAt() {
        Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2), 1.0e-10);
        for (double a = -2.0; a < 2.0; a += 0.2) {
            Point<Euclidean1D> pA = new Vector1D(a);
            Point<Euclidean2D> 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((Vector1D) pA, o);
                Assert.assertEquals(a, (l.toSubSpace(point)).getX(), 1.0e-10);
                Assert.assertEquals(o, l.getOffset(point),   1.0e-10);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.geometry.euclidean.twod.Line

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.