org.apache.commons.math3.geometry.partitioning.Region Java Examples

The following examples show how to use org.apache.commons.math3.geometry.partitioning.Region. 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: ArcTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testArc() {
    Arc arc = new Arc(2.3, 5.7, 1.0e-10);
    Assert.assertEquals(3.4, arc.getSize(), 1.0e-10);
    Assert.assertEquals(4.0, arc.getBarycenter(), 1.0e-10);
    Assert.assertEquals(Region.Location.BOUNDARY, arc.checkPoint(2.3));
    Assert.assertEquals(Region.Location.BOUNDARY, arc.checkPoint(5.7));
    Assert.assertEquals(Region.Location.OUTSIDE,  arc.checkPoint(1.2));
    Assert.assertEquals(Region.Location.OUTSIDE,  arc.checkPoint(8.5));
    Assert.assertEquals(Region.Location.INSIDE,   arc.checkPoint(8.7));
    Assert.assertEquals(Region.Location.INSIDE,   arc.checkPoint(3.0));
    Assert.assertEquals(2.3, arc.getInf(), 1.0e-10);
    Assert.assertEquals(5.7, arc.getSup(), 1.0e-10);
    Assert.assertEquals(4.0, arc.getBarycenter(), 1.0e-10);
    Assert.assertEquals(3.4, arc.getSize(), 1.0e-10);
}
 
Example #2
Source File: IntervalsSetTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInfinite() {
    IntervalsSet set = new IntervalsSet(9.0, Double.POSITIVE_INFINITY);
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(9.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.4)));
    for (double e = 1.0; e <= 6.0; e += 1.0) {
        Assert.assertEquals(Region.Location.INSIDE,
                            set.checkPoint(new Vector1D(FastMath.pow(10.0, e))));
    }
    Assert.assertTrue(Double.isInfinite(set.getSize()));
    Assert.assertEquals(9.0, set.getInf(), 1.0e-10);
    Assert.assertTrue(Double.isInfinite(set.getSup()));

    set = (IntervalsSet) new RegionFactory<Euclidean1D>().getComplement(set);
    Assert.assertEquals(9.0, set.getSup(), 1.0e-10);
    Assert.assertTrue(Double.isInfinite(set.getInf()));

}
 
Example #3
Source File: PolyhedronsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param facet boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean3D> facet, final boolean reversed) {

    final Region<Euclidean2D> polygon = ((SubPlane) facet).getRemainingRegion();
    final double area    = polygon.getSize();

    if (Double.isInfinite(area)) {
        setSize(Double.POSITIVE_INFINITY);
        setBarycenter(Vector3D.NaN);
    } else {

        final Plane    plane  = (Plane) facet.getHyperplane();
        final Vector3D facetB = plane.toSpace(polygon.getBarycenter());
        double   scaled = area * facetB.dotProduct(plane.getNormal());
        if (reversed) {
            scaled = -scaled;
        }

        setSize(getSize() + scaled);
        setBarycenter(new Vector3D(1.0, (Vector3D) getBarycenter(), scaled, facetB));

    }

}
 
Example #4
Source File: PolyhedronsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Build a parallellepipedic box boundary.
 * @param xMin low bound along the x direction
 * @param xMax high bound along the x direction
 * @param yMin low bound along the y direction
 * @param yMax high bound along the y direction
 * @param zMin low bound along the z direction
 * @param zMax high bound along the z direction
 * @param tolerance tolerance below which points are considered identical
 * @return boundary tree
 * @since 3.3
 */
private static BSPTree<Euclidean3D> buildBoundary(final double xMin, final double xMax,
                                                  final double yMin, final double yMax,
                                                  final double zMin, final double zMax,
                                                  final double tolerance) {
    if ((xMin >= xMax - tolerance) || (yMin >= yMax - tolerance) || (zMin >= zMax - tolerance)) {
        // too thin box, build an empty polygons set
        return new BSPTree<Euclidean3D>(Boolean.FALSE);
    }
    final Plane pxMin = new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I, tolerance);
    final Plane pxMax = new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I,  tolerance);
    final Plane pyMin = new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J, tolerance);
    final Plane pyMax = new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J,  tolerance);
    final Plane pzMin = new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K, tolerance);
    final Plane pzMax = new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K,  tolerance);
    @SuppressWarnings("unchecked")
    final Region<Euclidean3D> boundary =
    new RegionFactory<Euclidean3D>().buildConvex(pxMin, pxMax, pyMin, pyMax, pzMin, pzMax);
    return boundary.getTree(false);
}
 
Example #5
Source File: ConvexHullGenerator2DAbstractTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
protected final void checkPointsInsideHullRegion(final Collection<Vector2D> points,
                                                 final ConvexHull2D hull,
                                                 final boolean includesCollinearPoints) {

    final Collection<Vector2D> hullVertices = Arrays.asList(hull.getVertices());
    final Region<Euclidean2D> region = hull.createRegion();

    for (final Vector2D p : points) {
        Location location = region.checkPoint(p);
        Assert.assertTrue(location != Location.OUTSIDE);

        if (location == Location.BOUNDARY && includesCollinearPoints) {
            Assert.assertTrue(hullVertices.contains(p));
        }
    }
}
 
Example #6
Source File: PolyhedronsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param facet boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean3D> facet, final boolean reversed) {

    final Region<Euclidean2D> polygon = ((SubPlane) facet).getRemainingRegion();
    final double area    = polygon.getSize();

    if (Double.isInfinite(area)) {
        setSize(Double.POSITIVE_INFINITY);
        setBarycenter(Vector3D.NaN);
    } else {

        final Plane    plane  = (Plane) facet.getHyperplane();
        final Vector3D facetB = plane.toSpace(polygon.getBarycenter());
        double   scaled = area * facetB.dotProduct(plane.getNormal());
        if (reversed) {
            scaled = -scaled;
        }

        setSize(getSize() + scaled);
        setBarycenter(new Vector3D(1.0, (Vector3D) getBarycenter(), scaled, facetB));

    }

}
 
Example #7
Source File: ConvexHullGenerator2DAbstractTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
protected final void checkPointsInsideHullRegion(final Collection<Vector2D> points,
                                                 final ConvexHull2D hull,
                                                 final boolean includesCollinearPoints) {

    final Collection<Vector2D> hullVertices = Arrays.asList(hull.getVertices());
    final Region<Euclidean2D> region = hull.createRegion();

    for (final Vector2D p : points) {
        Location location = region.checkPoint(p);
        Assert.assertTrue(location != Location.OUTSIDE);

        if (location == Location.BOUNDARY && includesCollinearPoints) {
            Assert.assertTrue(hullVertices.contains(p));
        }
    }
}
 
Example #8
Source File: PolyhedronsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param facet boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean3D> facet, final boolean reversed) {

    final Region<Euclidean2D> polygon = ((SubPlane) facet).getRemainingRegion();
    final double area    = polygon.getSize();

    if (Double.isInfinite(area)) {
        setSize(Double.POSITIVE_INFINITY);
        setBarycenter(Vector3D.NaN);
    } else {

        final Plane    plane  = (Plane) facet.getHyperplane();
        final Vector3D facetB = plane.toSpace(polygon.getBarycenter());
        double   scaled = area * facetB.dotProduct(plane.getNormal());
        if (reversed) {
            scaled = -scaled;
        }

        setSize(getSize() + scaled);
        setBarycenter(new Vector3D(1.0, (Vector3D) getBarycenter(), scaled, facetB));

    }

}
 
Example #9
Source File: IntervalsSetTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInfinite() {
    IntervalsSet set = new IntervalsSet(9.0, Double.POSITIVE_INFINITY);
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(9.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.4)));
    for (double e = 1.0; e <= 6.0; e += 1.0) {
        Assert.assertEquals(Region.Location.INSIDE,
                            set.checkPoint(new Vector1D(FastMath.pow(10.0, e))));
    }
    Assert.assertTrue(Double.isInfinite(set.getSize()));
    Assert.assertEquals(9.0, set.getInf(), 1.0e-10);
    Assert.assertTrue(Double.isInfinite(set.getSup()));

    set = (IntervalsSet) new RegionFactory<Euclidean1D>().getComplement(set);
    Assert.assertEquals(9.0, set.getSup(), 1.0e-10);
    Assert.assertTrue(Double.isInfinite(set.getInf()));

}
 
Example #10
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDisjointPolygons() {
    Vector2D[][] vertices = new Vector2D[][] {
        new Vector2D[] {
            new Vector2D(0.0, 1.0),
            new Vector2D(2.0, 1.0),
            new Vector2D(1.0, 2.0)
        }, new Vector2D[] {
            new Vector2D(4.0, 0.0),
            new Vector2D(5.0, 1.0),
            new Vector2D(3.0, 1.0)
        }
    };
    PolygonsSet set = buildSet(vertices);
    Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector2D(1.0, 1.5)));
    checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
        new Vector2D(1.0, 1.5),
        new Vector2D(4.5, 0.8)
    });
    checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
        new Vector2D(1.0, 0.0),
        new Vector2D(3.5, 1.2),
        new Vector2D(2.5, 1.0),
        new Vector2D(3.0, 4.0)
    });
    checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
        new Vector2D(1.0, 1.0),
        new Vector2D(3.5, 0.5),
        new Vector2D(0.0, 1.0)
    });
    checkVertices(set.getVertices(), vertices);
}
 
Example #11
Source File: IntervalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInfinite() {
    Interval interval = new Interval(9.0, Double.POSITIVE_INFINITY);
    Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(9.0, 1.0e-10));
    Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(8.4, 1.0e-10));
    for (double e = 1.0; e <= 6.0; e += 1.0) {
        Assert.assertEquals(Region.Location.INSIDE,
                            interval.checkPoint(FastMath.pow(10.0, e), 1.0e-10));
    }
    Assert.assertTrue(Double.isInfinite(interval.getSize()));
    Assert.assertEquals(9.0, interval.getInf(), 1.0e-10);
    Assert.assertTrue(Double.isInfinite(interval.getSup()));

}
 
Example #12
Source File: ConvexHull2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public Region<Euclidean2D> createRegion() throws InsufficientDataException {
    if (vertices.length < 3) {
        throw new InsufficientDataException();
    }
    final RegionFactory<Euclidean2D> factory = new RegionFactory<Euclidean2D>();
    final Segment[] segments = retrieveLineSegments();
    final Line[] lineArray = new Line[segments.length];
    for (int i = 0; i < segments.length; i++) {
        lineArray[i] = segments[i].getLine();
    }
    return factory.buildConvex(lineArray);
}
 
Example #13
Source File: NPEfix10_ten_t.java    From coming with MIT License 5 votes vote down vote up
/** Build a parallellepipedic box boundary.
     * @param xMin low bound along the x direction
     * @param xMax high bound along the x direction
     * @param yMin low bound along the y direction
     * @param yMax high bound along the y direction
     * @param zMin low bound along the z direction
     * @param zMax high bound along the z direction
     * @param tolerance tolerance below which points are considered identical
     * @return boundary tree
     * @since 3.3
     */
    private static BSPTree<Euclidean3D> buildBoundary(final double xMin, final double xMax,
                                                      final double yMin, final double yMax,
                                                      final double zMin, final double zMax,
                                                      final double tolerance) {
//    	FIX
//        if ((xMin >= xMax - tolerance) || (yMin >= yMax - tolerance) || (zMin >= zMax - tolerance)) {
//            // too thin box, build an empty polygons set
//            return new BSPTree<Euclidean3D>(Boolean.FALSE);
//        }

        if ((xMin >= xMax - tolerance) || (yMin >= yMax - tolerance) || (zMin >= zMax - tolerance)) {
            // too thin box, build an empty polygons set
            return new BSPTree<Euclidean3D>(Boolean.FALSE);
        }



        final Plane pxMin = new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I, tolerance);
        final Plane pxMax = new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I,  tolerance);
        final Plane pyMin = new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J, tolerance);
        final Plane pyMax = new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J,  tolerance);
        final Plane pzMin = new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K, tolerance);
        final Plane pzMax = new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K,  tolerance);
        @SuppressWarnings("unchecked")
        final Region<Euclidean3D> boundary =
                new RegionFactory<Euclidean3D>().buildConvex(pxMin, pxMax, pyMin, pyMax, pzMin, pzMax);
        return boundary.getTree(false);
    }
 
Example #14
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSimplyConnected() {
    Vector2D[][] vertices = new Vector2D[][] {
        new Vector2D[] {
            new Vector2D(36.0, 22.0),
            new Vector2D(39.0, 32.0),
            new Vector2D(19.0, 32.0),
            new Vector2D( 6.0, 16.0),
            new Vector2D(31.0, 10.0),
            new Vector2D(42.0, 16.0),
            new Vector2D(34.0, 20.0),
            new Vector2D(29.0, 19.0),
            new Vector2D(23.0, 22.0),
            new Vector2D(33.0, 25.0)
        }
    };
    PolygonsSet set = buildSet(vertices);
    Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0)));
    checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
        new Vector2D(30.0, 15.0),
        new Vector2D(15.0, 20.0),
        new Vector2D(24.0, 25.0),
        new Vector2D(35.0, 30.0),
        new Vector2D(19.0, 17.0)
    });
    checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
        new Vector2D(50.0, 30.0),
        new Vector2D(30.0, 35.0),
        new Vector2D(10.0, 25.0),
        new Vector2D(10.0, 10.0),
        new Vector2D(40.0, 10.0),
        new Vector2D(50.0, 15.0),
        new Vector2D(30.0, 22.0)
    });
    checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
        new Vector2D(30.0, 32.0),
        new Vector2D(34.0, 20.0)
    });
    checkVertices(set.getVertices(), vertices);
}
 
Example #15
Source File: PolyhedronsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTetrahedron() throws MathArithmeticException {
    Vector3D vertex1 = new Vector3D(1, 2, 3);
    Vector3D vertex2 = new Vector3D(2, 2, 4);
    Vector3D vertex3 = new Vector3D(2, 3, 3);
    Vector3D vertex4 = new Vector3D(1, 3, 4);
    @SuppressWarnings("unchecked")
    PolyhedronsSet tree =
        (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex(
            new Plane(vertex3, vertex2, vertex1),
            new Plane(vertex2, vertex3, vertex4),
            new Plane(vertex4, vertex3, vertex1),
            new Plane(vertex1, vertex2, vertex4));
    Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10);
    Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10);
    Vector3D barycenter = (Vector3D) tree.getBarycenter();
    Assert.assertEquals(1.5, barycenter.getX(), 1.0e-10);
    Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10);
    Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10);
    double third = 1.0 / 3.0;
    checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
        vertex1, vertex2, vertex3, vertex4,
        new Vector3D(third, vertex1, third, vertex2, third, vertex3),
        new Vector3D(third, vertex2, third, vertex3, third, vertex4),
        new Vector3D(third, vertex3, third, vertex4, third, vertex1),
        new Vector3D(third, vertex4, third, vertex1, third, vertex2)
    });
    checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
        new Vector3D(1, 2, 4),
        new Vector3D(2, 2, 3),
        new Vector3D(2, 3, 4),
        new Vector3D(1, 3, 3)
    });
}
 
Example #16
Source File: PolyhedronsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTetrahedron() throws MathArithmeticException {
    Vector3D vertex1 = new Vector3D(1, 2, 3);
    Vector3D vertex2 = new Vector3D(2, 2, 4);
    Vector3D vertex3 = new Vector3D(2, 3, 3);
    Vector3D vertex4 = new Vector3D(1, 3, 4);
    @SuppressWarnings("unchecked")
    PolyhedronsSet tree =
        (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex(
            new Plane(vertex3, vertex2, vertex1, 1.0e-10),
            new Plane(vertex2, vertex3, vertex4, 1.0e-10),
            new Plane(vertex4, vertex3, vertex1, 1.0e-10),
            new Plane(vertex1, vertex2, vertex4, 1.0e-10));
    Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10);
    Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10);
    Vector3D barycenter = (Vector3D) tree.getBarycenter();
    Assert.assertEquals(1.5, barycenter.getX(), 1.0e-10);
    Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10);
    Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10);
    double third = 1.0 / 3.0;
    checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
        vertex1, vertex2, vertex3, vertex4,
        new Vector3D(third, vertex1, third, vertex2, third, vertex3),
        new Vector3D(third, vertex2, third, vertex3, third, vertex4),
        new Vector3D(third, vertex3, third, vertex4, third, vertex1),
        new Vector3D(third, vertex4, third, vertex1, third, vertex2)
    });
    checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
        new Vector3D(1, 2, 4),
        new Vector3D(2, 2, 3),
        new Vector3D(2, 3, 4),
        new Vector3D(1, 3, 3)
    });
}
 
Example #17
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDisjointPolygons() {
    Vector2D[][] vertices = new Vector2D[][] {
        new Vector2D[] {
            new Vector2D(0.0, 1.0),
            new Vector2D(2.0, 1.0),
            new Vector2D(1.0, 2.0)
        }, new Vector2D[] {
            new Vector2D(4.0, 0.0),
            new Vector2D(5.0, 1.0),
            new Vector2D(3.0, 1.0)
        }
    };
    PolygonsSet set = buildSet(vertices);
    Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector2D(1.0, 1.5)));
    checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
        new Vector2D(1.0, 1.5),
        new Vector2D(4.5, 0.8)
    });
    checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
        new Vector2D(1.0, 0.0),
        new Vector2D(3.5, 1.2),
        new Vector2D(2.5, 1.0),
        new Vector2D(3.0, 4.0)
    });
    checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
        new Vector2D(1.0, 1.0),
        new Vector2D(3.5, 0.5),
        new Vector2D(0.0, 1.0)
    });
    checkVertices(set.getVertices(), vertices);
}
 
Example #18
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSimplyConnected() {
    Vector2D[][] vertices = new Vector2D[][] {
        new Vector2D[] {
            new Vector2D(36.0, 22.0),
            new Vector2D(39.0, 32.0),
            new Vector2D(19.0, 32.0),
            new Vector2D( 6.0, 16.0),
            new Vector2D(31.0, 10.0),
            new Vector2D(42.0, 16.0),
            new Vector2D(34.0, 20.0),
            new Vector2D(29.0, 19.0),
            new Vector2D(23.0, 22.0),
            new Vector2D(33.0, 25.0)
        }
    };
    PolygonsSet set = buildSet(vertices);
    Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0)));
    checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
        new Vector2D(30.0, 15.0),
        new Vector2D(15.0, 20.0),
        new Vector2D(24.0, 25.0),
        new Vector2D(35.0, 30.0),
        new Vector2D(19.0, 17.0)
    });
    checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
        new Vector2D(50.0, 30.0),
        new Vector2D(30.0, 35.0),
        new Vector2D(10.0, 25.0),
        new Vector2D(10.0, 10.0),
        new Vector2D(40.0, 10.0),
        new Vector2D(50.0, 15.0),
        new Vector2D(30.0, 22.0)
    });
    checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
        new Vector2D(30.0, 32.0),
        new Vector2D(34.0, 20.0)
    });
    checkVertices(set.getVertices(), vertices);
}
 
Example #19
Source File: PolyhedronsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTetrahedron() throws MathArithmeticException {
    Vector3D vertex1 = new Vector3D(1, 2, 3);
    Vector3D vertex2 = new Vector3D(2, 2, 4);
    Vector3D vertex3 = new Vector3D(2, 3, 3);
    Vector3D vertex4 = new Vector3D(1, 3, 4);
    @SuppressWarnings("unchecked")
    PolyhedronsSet tree =
        (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex(
            new Plane(vertex3, vertex2, vertex1),
            new Plane(vertex2, vertex3, vertex4),
            new Plane(vertex4, vertex3, vertex1),
            new Plane(vertex1, vertex2, vertex4));
    Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10);
    Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10);
    Vector3D barycenter = (Vector3D) tree.getBarycenter();
    Assert.assertEquals(1.5, barycenter.getX(), 1.0e-10);
    Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10);
    Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10);
    double third = 1.0 / 3.0;
    checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
        vertex1, vertex2, vertex3, vertex4,
        new Vector3D(third, vertex1, third, vertex2, third, vertex3),
        new Vector3D(third, vertex2, third, vertex3, third, vertex4),
        new Vector3D(third, vertex3, third, vertex4, third, vertex1),
        new Vector3D(third, vertex4, third, vertex1, third, vertex2)
    });
    checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
        new Vector3D(1, 2, 4),
        new Vector3D(2, 2, 3),
        new Vector3D(2, 3, 4),
        new Vector3D(1, 3, 3)
    });
}
 
Example #20
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testChoppedHexagon() {
    double pi6   = FastMath.PI / 6.0;
    double sqrt3 = FastMath.sqrt(3.0);
    SubLine[] hyp = {
        new Line(new Vector2D(   0.0, 1.0),  5 * pi6, 1.0e-10).wholeHyperplane(),
        new Line(new Vector2D(-sqrt3, 1.0),  7 * pi6, 1.0e-10).wholeHyperplane(),
        new Line(new Vector2D(-sqrt3, 1.0),  9 * pi6, 1.0e-10).wholeHyperplane(),
        new Line(new Vector2D(-sqrt3, 0.0), 11 * pi6, 1.0e-10).wholeHyperplane(),
        new Line(new Vector2D(   0.0, 0.0), 13 * pi6, 1.0e-10).wholeHyperplane(),
        new Line(new Vector2D(   0.0, 1.0),  3 * pi6, 1.0e-10).wholeHyperplane(),
        new Line(new Vector2D(-5.0 * sqrt3 / 6.0, 0.0), 9 * pi6, 1.0e-10).wholeHyperplane()
    };
    hyp[1] = (SubLine) hyp[1].split(hyp[0].getHyperplane()).getMinus();
    hyp[2] = (SubLine) hyp[2].split(hyp[1].getHyperplane()).getMinus();
    hyp[3] = (SubLine) hyp[3].split(hyp[2].getHyperplane()).getMinus();
    hyp[4] = (SubLine) hyp[4].split(hyp[3].getHyperplane()).getMinus().split(hyp[0].getHyperplane()).getMinus();
    hyp[5] = (SubLine) hyp[5].split(hyp[4].getHyperplane()).getMinus().split(hyp[0].getHyperplane()).getMinus();
    hyp[6] = (SubLine) hyp[6].split(hyp[3].getHyperplane()).getMinus().split(hyp[1].getHyperplane()).getMinus();
    BSPTree<Euclidean2D> tree = new BSPTree<Euclidean2D>(Boolean.TRUE);
    for (int i = hyp.length - 1; i >= 0; --i) {
        tree = new BSPTree<Euclidean2D>(hyp[i], new BSPTree<Euclidean2D>(Boolean.FALSE), tree, null);
    }
    PolygonsSet set = new PolygonsSet(tree, 1.0e-10);
    SubLine splitter =
        new Line(new Vector2D(-2.0 * sqrt3 / 3.0, 0.0), 9 * pi6, 1.0e-10).wholeHyperplane();
    PolygonsSet slice =
        new PolygonsSet(new BSPTree<Euclidean2D>(splitter,
                                                 set.getTree(false).split(splitter).getPlus(),
                                                 new BSPTree<Euclidean2D>(Boolean.FALSE), null),
                        1.0e-10);
    Assert.assertEquals(Region.Location.OUTSIDE,
                        slice.checkPoint(new Vector2D(0.1, 0.5)));
    Assert.assertEquals(11.0 / 3.0, slice.getBoundarySize(), 1.0e-10);

}
 
Example #21
Source File: PolyhedronsSet.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Build a parallellepipedic box boundary.
 * @param xMin low bound along the x direction
 * @param xMax high bound along the x direction
 * @param yMin low bound along the y direction
 * @param yMax high bound along the y direction
 * @param zMin low bound along the z direction
 * @param zMax high bound along the z direction
 * @return boundary tree
 */
private static BSPTree<Euclidean3D> buildBoundary(final double xMin, final double xMax,
                                                  final double yMin, final double yMax,
                                                  final double zMin, final double zMax) {
    final Plane pxMin = new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I);
    final Plane pxMax = new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I);
    final Plane pyMin = new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J);
    final Plane pyMax = new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J);
    final Plane pzMin = new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K);
    final Plane pzMax = new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K);
    @SuppressWarnings("unchecked")
    final Region<Euclidean3D> boundary =
    new RegionFactory<Euclidean3D>().buildConvex(pxMin, pxMax, pyMin, pyMax, pzMin, pzMax);
    return boundary.getTree(false);
}
 
Example #22
Source File: PolyhedronsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTetrahedron() throws MathArithmeticException {
    Vector3D vertex1 = new Vector3D(1, 2, 3);
    Vector3D vertex2 = new Vector3D(2, 2, 4);
    Vector3D vertex3 = new Vector3D(2, 3, 3);
    Vector3D vertex4 = new Vector3D(1, 3, 4);
    @SuppressWarnings("unchecked")
    PolyhedronsSet tree =
        (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex(
            new Plane(vertex3, vertex2, vertex1, 1.0e-10),
            new Plane(vertex2, vertex3, vertex4, 1.0e-10),
            new Plane(vertex4, vertex3, vertex1, 1.0e-10),
            new Plane(vertex1, vertex2, vertex4, 1.0e-10));
    Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10);
    Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10);
    Vector3D barycenter = (Vector3D) tree.getBarycenter();
    Assert.assertEquals(1.5, barycenter.getX(), 1.0e-10);
    Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10);
    Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10);
    double third = 1.0 / 3.0;
    checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
        vertex1, vertex2, vertex3, vertex4,
        new Vector3D(third, vertex1, third, vertex2, third, vertex3),
        new Vector3D(third, vertex2, third, vertex3, third, vertex4),
        new Vector3D(third, vertex3, third, vertex4, third, vertex1),
        new Vector3D(third, vertex4, third, vertex1, third, vertex2)
    });
    checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
        new Vector3D(1, 2, 4),
        new Vector3D(2, 2, 3),
        new Vector3D(2, 3, 4),
        new Vector3D(1, 3, 3)
    });
}
 
Example #23
Source File: IntervalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInterval() {
    Interval interval = new Interval(2.3, 5.7);
    Assert.assertEquals(3.4, interval.getSize(), 1.0e-10);
    Assert.assertEquals(4.0, interval.getBarycenter(), 1.0e-10);
    Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(2.3, 1.0e-10));
    Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(5.7, 1.0e-10));
    Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(1.2, 1.0e-10));
    Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(8.7, 1.0e-10));
    Assert.assertEquals(Region.Location.INSIDE,   interval.checkPoint(3.0, 1.0e-10));
    Assert.assertEquals(2.3, interval.getInf(), 1.0e-10);
    Assert.assertEquals(5.7, interval.getSup(), 1.0e-10);
}
 
Example #24
Source File: IntervalsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMultiple() {
    RegionFactory<Euclidean1D> factory = new RegionFactory<Euclidean1D>();
    IntervalsSet set = (IntervalsSet)
    factory.intersection(factory.union(factory.difference(new IntervalsSet(1.0, 6.0, 1.0e-10),
                                                          new IntervalsSet(3.0, 5.0, 1.0e-10)),
                                                          new IntervalsSet(9.0, Double.POSITIVE_INFINITY, 1.0e-10)),
                                                          new IntervalsSet(Double.NEGATIVE_INFINITY, 11.0, 1.0e-10));
    Assert.assertEquals(5.0, set.getSize(), 1.0e-10);
    Assert.assertEquals(5.9, ((Vector1D) set.getBarycenter()).getX(), 1.0e-10);
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(0.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(4.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(12.0)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(1.2)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(5.9)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(9.01)));
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(5.0)));
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(11.0)));
    Assert.assertEquals( 1.0, set.getInf(), 1.0e-10);
    Assert.assertEquals(11.0, set.getSup(), 1.0e-10);

    List<Interval> list = set.asList();
    Assert.assertEquals(3, list.size());
    Assert.assertEquals( 1.0, list.get(0).getInf(), 1.0e-10);
    Assert.assertEquals( 3.0, list.get(0).getSup(), 1.0e-10);
    Assert.assertEquals( 5.0, list.get(1).getInf(), 1.0e-10);
    Assert.assertEquals( 6.0, list.get(1).getSup(), 1.0e-10);
    Assert.assertEquals( 9.0, list.get(2).getInf(), 1.0e-10);
    Assert.assertEquals(11.0, list.get(2).getSup(), 1.0e-10);

}
 
Example #25
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSimplyConnected() {
    Vector2D[][] vertices = new Vector2D[][] {
        new Vector2D[] {
            new Vector2D(36.0, 22.0),
            new Vector2D(39.0, 32.0),
            new Vector2D(19.0, 32.0),
            new Vector2D( 6.0, 16.0),
            new Vector2D(31.0, 10.0),
            new Vector2D(42.0, 16.0),
            new Vector2D(34.0, 20.0),
            new Vector2D(29.0, 19.0),
            new Vector2D(23.0, 22.0),
            new Vector2D(33.0, 25.0)
        }
    };
    PolygonsSet set = buildSet(vertices);
    Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0)));
    checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
        new Vector2D(30.0, 15.0),
        new Vector2D(15.0, 20.0),
        new Vector2D(24.0, 25.0),
        new Vector2D(35.0, 30.0),
        new Vector2D(19.0, 17.0)
    });
    checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
        new Vector2D(50.0, 30.0),
        new Vector2D(30.0, 35.0),
        new Vector2D(10.0, 25.0),
        new Vector2D(10.0, 10.0),
        new Vector2D(40.0, 10.0),
        new Vector2D(50.0, 15.0),
        new Vector2D(30.0, 22.0)
    });
    checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
        new Vector2D(30.0, 32.0),
        new Vector2D(34.0, 20.0)
    });
    checkVertices(set.getVertices(), vertices);
}
 
Example #26
Source File: IntervalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInfinite() {
    Interval interval = new Interval(9.0, Double.POSITIVE_INFINITY);
    Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(9.0, 1.0e-10));
    Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(8.4, 1.0e-10));
    for (double e = 1.0; e <= 6.0; e += 1.0) {
        Assert.assertEquals(Region.Location.INSIDE,
                            interval.checkPoint(FastMath.pow(10.0, e), 1.0e-10));
    }
    Assert.assertTrue(Double.isInfinite(interval.getSize()));
    Assert.assertEquals(9.0, interval.getInf(), 1.0e-10);
    Assert.assertTrue(Double.isInfinite(interval.getSup()));

}
 
Example #27
Source File: IntervalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testInterval() {
    Interval interval = new Interval(2.3, 5.7);
    Assert.assertEquals(3.4, interval.getSize(), 1.0e-10);
    Assert.assertEquals(4.0, interval.getBarycenter(), 1.0e-10);
    Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(2.3, 1.0e-10));
    Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(5.7, 1.0e-10));
    Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(1.2, 1.0e-10));
    Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(8.7, 1.0e-10));
    Assert.assertEquals(Region.Location.INSIDE,   interval.checkPoint(3.0, 1.0e-10));
    Assert.assertEquals(2.3, interval.getInf(), 1.0e-10);
    Assert.assertEquals(5.7, interval.getSup(), 1.0e-10);
}
 
Example #28
Source File: PolyhedronsSet.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Build a parallellepipedic box boundary.
 * @param xMin low bound along the x direction
 * @param xMax high bound along the x direction
 * @param yMin low bound along the y direction
 * @param yMax high bound along the y direction
 * @param zMin low bound along the z direction
 * @param zMax high bound along the z direction
 * @return boundary tree
 */
private static BSPTree<Euclidean3D> buildBoundary(final double xMin, final double xMax,
                                                  final double yMin, final double yMax,
                                                  final double zMin, final double zMax) {
    final Plane pxMin = new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I);
    final Plane pxMax = new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I);
    final Plane pyMin = new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J);
    final Plane pyMax = new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J);
    final Plane pzMin = new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K);
    final Plane pzMax = new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K);
    @SuppressWarnings("unchecked")
    final Region<Euclidean3D> boundary =
    new RegionFactory<Euclidean3D>().buildConvex(pxMin, pxMax, pyMin, pyMax, pzMin, pzMax);
    return boundary.getTree(false);
}
 
Example #29
Source File: ArcsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testArc() {
    ArcsSet set = new ArcsSet(2.3, 5.7, 1.0e-10);
    Assert.assertEquals(3.4, set.getSize(), 1.0e-10);
    Assert.assertEquals(1.0e-10, set.getTolerance(), 1.0e-20);
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(2.3)));
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.7)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new S1Point(1.2)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new S1Point(8.5)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new S1Point(8.7)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new S1Point(3.0)));
    Assert.assertEquals(1, set.asList().size());
    Assert.assertEquals(2.3, set.asList().get(0).getInf(), 1.0e-10);
    Assert.assertEquals(5.7, set.asList().get(0).getSup(), 1.0e-10);
}
 
Example #30
Source File: ArcTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testFullCircle() {
    Arc arc = new Arc(9.0, 9.0, 1.0e-10);
    // no boundaries on a full circle
    Assert.assertEquals(Region.Location.INSIDE, arc.checkPoint(9.0));
    Assert.assertEquals(.0, arc.getInf(), 1.0e-10);
    Assert.assertEquals(MathUtils.TWO_PI, arc.getSup(), 1.0e-10);
    Assert.assertEquals(2.0 * FastMath.PI, arc.getSize(), 1.0e-10);
    for (double alpha = -20.0; alpha <= 20.0; alpha += 0.1) {
        Assert.assertEquals(Region.Location.INSIDE, arc.checkPoint(alpha));
    }
}