org.apache.commons.math3.geometry.partitioning.Region.Location Java Examples
The following examples show how to use
org.apache.commons.math3.geometry.partitioning.Region.Location.
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: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { // compute the intersection on infinite line Vector3D v1D = line.intersection(subLine.line); // check location of point with respect to first sub-line Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D)); // check location of point with respect to second sub-line Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } }
Example #2
Source File: ArcsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSplitAtEnd() { ArcsSet set = new ArcsSet(1.0e-10); Arc arc = new Arc(FastMath.PI, MathUtils.TWO_PI, 1.0e-10); ArcsSet.Split split = set.split(arc); for (double alpha = 0.01; alpha < MathUtils.TWO_PI; alpha += 0.01) { S1Point p = new S1Point(alpha); if (alpha > FastMath.PI) { Assert.assertEquals(Location.OUTSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.INSIDE, split.getMinus().checkPoint(p)); } else { Assert.assertEquals(Location.INSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.OUTSIDE, split.getMinus().checkPoint(p)); } } S1Point zero = new S1Point(0.0); Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(zero)); Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(zero)); S1Point pi = new S1Point(FastMath.PI); Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(pi)); Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(pi)); }
Example #3
Source File: SubLine_s.java From coming with MIT License | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #4
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testIssue880Simplified() { Vector2D[] vertices1 = new Vector2D[] { new Vector2D( 90.13595870833188, 38.33604606376991), new Vector2D( 90.14047850603913, 38.34600084496253), new Vector2D( 90.11045289492762, 38.36801537312368), new Vector2D( 90.10871471476526, 38.36878044144294), new Vector2D( 90.10424901707671, 38.374300101757), new Vector2D( 90.0979455456843, 38.373578376172475), new Vector2D( 90.09081227075944, 38.37526295920463), new Vector2D( 90.09081378927135, 38.375193883266434) }; PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32))); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355))); }
Example #5
Source File: Math_4_SubLine_t.java From coming with MIT License | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); if (v2D == null) { return null; } // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #6
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); if (v2D == null) { return null; } // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace((Point<Euclidean2D>) v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace((Point<Euclidean2D>) v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #7
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #8
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { // compute the intersection on infinite line Vector3D v1D = line.intersection(subLine.line); // check location of point with respect to first sub-line Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D)); // check location of point with respect to second sub-line Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } }
Example #9
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { // compute the intersection on infinite line Vector3D v1D = line.intersection(subLine.line); if (v1D == null) { return null; } // check location of point with respect to first sub-line Location loc1 = remainingRegion.checkPoint((Point<Euclidean1D>) line.toSubSpace((Point<Euclidean3D>) v1D)); // check location of point with respect to second sub-line Location loc2 = subLine.remainingRegion.checkPoint((Point<Euclidean1D>) subLine.line.toSubSpace((Point<Euclidean3D>) v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } }
Example #10
Source File: Util.java From AILibs with GNU Affero General Public License v3.0 | 6 votes |
private static String getParamValue(final Parameter p, final String assignedValue, final boolean resolveIntervals) { if (assignedValue == null) { throw new IllegalArgumentException("Cannot determine true value for assigned param value " + assignedValue + " for parameter " + p.getName()); } String interpretedValue = ""; if (p.isNumeric()) { if (resolveIntervals) { NumericParameterDomain np = (NumericParameterDomain) p.getDefaultDomain(); List<String> vals = SetUtil.unserializeList(assignedValue); Interval interval = new Interval(Double.valueOf(vals.get(0)), Double.valueOf(vals.get(1))); if (np.isInteger()) { interpretedValue = String.valueOf((int) Math.round(interval.getBarycenter())); } else { interpretedValue = String.valueOf(interval.checkPoint((double) p.getDefaultValue(), 0.001) == Location.INSIDE ? (double) p.getDefaultValue() : interval.getBarycenter()); } } else { interpretedValue = assignedValue; } } else if (p.getDefaultDomain() instanceof CategoricalParameterDomain) { interpretedValue = assignedValue; } else { throw new UnsupportedOperationException("No support for parameters of type " + p.getClass().getName()); } return interpretedValue; }
Example #11
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testIssue880Simplified() { Vector2D[] vertices1 = new Vector2D[] { new Vector2D( 90.13595870833188, 38.33604606376991), new Vector2D( 90.14047850603913, 38.34600084496253), new Vector2D( 90.11045289492762, 38.36801537312368), new Vector2D( 90.10871471476526, 38.36878044144294), new Vector2D( 90.10424901707671, 38.374300101757), new Vector2D( 90.0979455456843, 38.373578376172475), new Vector2D( 90.09081227075944, 38.37526295920463), new Vector2D( 90.09081378927135, 38.375193883266434) }; PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32))); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355))); }
Example #12
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { // compute the intersection on infinite line Vector3D v1D = line.intersection(subLine.line); if (v1D == null) { return null; } // check location of point with respect to first sub-line Location loc1 = remainingRegion.checkPoint((Point<Euclidean1D>) line.toSubSpace((Point<Euclidean3D>) v1D)); // check location of point with respect to second sub-line Location loc2 = subLine.remainingRegion.checkPoint((Point<Euclidean1D>) subLine.line.toSubSpace((Point<Euclidean3D>) v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } }
Example #13
Source File: ArcsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSplitAtEnd() { ArcsSet set = new ArcsSet(1.0e-10); Arc arc = new Arc(FastMath.PI, MathUtils.TWO_PI, 1.0e-10); ArcsSet.Split split = set.split(arc); for (double alpha = 0.01; alpha < MathUtils.TWO_PI; alpha += 0.01) { S1Point p = new S1Point(alpha); if (alpha > FastMath.PI) { Assert.assertEquals(Location.OUTSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.INSIDE, split.getMinus().checkPoint(p)); } else { Assert.assertEquals(Location.INSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.OUTSIDE, split.getMinus().checkPoint(p)); } } S1Point zero = new S1Point(0.0); Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(zero)); Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(zero)); S1Point pi = new S1Point(FastMath.PI); Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(pi)); Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(pi)); }
Example #14
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testIssue880Simplified() { Vector2D[] vertices1 = new Vector2D[] { new Vector2D( 90.13595870833188, 38.33604606376991), new Vector2D( 90.14047850603913, 38.34600084496253), new Vector2D( 90.11045289492762, 38.36801537312368), new Vector2D( 90.10871471476526, 38.36878044144294), new Vector2D( 90.10424901707671, 38.374300101757), new Vector2D( 90.0979455456843, 38.373578376172475), new Vector2D( 90.09081227075944, 38.37526295920463), new Vector2D( 90.09081378927135, 38.375193883266434) }; PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32))); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355))); }
Example #15
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); if (v2D == null) { return null; } // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #16
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { // compute the intersection on infinite line Vector3D v1D = line.intersection(subLine.line); if (v1D == null) { return null; } // check location of point with respect to first sub-line Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D)); // check location of point with respect to second sub-line Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } }
Example #17
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #18
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { // compute the intersection on infinite line Vector3D v1D = line.intersection(subLine.line); // check location of point with respect to first sub-line Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D)); // check location of point with respect to second sub-line Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } }
Example #19
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** Get the intersection of the instance and another sub-line. * <p> * This method is related to the {@link Line#intersection(Line) * intersection} method in the {@link Line Line} class, but in addition * to compute the point along infinite lines, it also checks the point * lies on both sub-line ranges. * </p> * @param subLine other sub-line which may intersect instance * @param includeEndPoints if true, endpoints are considered to belong to * instance (i.e. they are closed sets) and may be returned, otherwise endpoints * are considered to not belong to instance (i.e. they are open sets) and intersection * occurring on endpoints lead to null being returned * @return the intersection point if there is one, null if the sub-lines don't intersect */ public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) { // retrieve the underlying lines Line line1 = (Line) getHyperplane(); Line line2 = (Line) subLine.getHyperplane(); // compute the intersection on infinite line Vector2D v2D = line1.intersection(line2); // check location of point with respect to first sub-line Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); // check location of point with respect to second sub-line Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null; } }
Example #20
Source File: SphericalPolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testPositiveOctantByVertices() { double tol = 0.01; double sinTol = FastMath.sin(tol); SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l)); for (int i = 0; i < 1000; ++i) { Vector3D v = new Vector3D(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v))); } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) { Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v))); } else { Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v))); } } }
Example #21
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testIssue880Simplified() { Vector2D[] vertices1 = new Vector2D[] { new Vector2D( 90.13595870833188, 38.33604606376991), new Vector2D( 90.14047850603913, 38.34600084496253), new Vector2D( 90.11045289492762, 38.36801537312368), new Vector2D( 90.10871471476526, 38.36878044144294), new Vector2D( 90.10424901707671, 38.374300101757), new Vector2D( 90.0979455456843, 38.373578376172475), new Vector2D( 90.09081227075944, 38.37526295920463), new Vector2D( 90.09081378927135, 38.375193883266434) }; PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32))); Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355))); }
Example #22
Source File: SphericalPolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testPositiveOctantByVertices() { double tol = 0.01; double sinTol = FastMath.sin(tol); SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l)); for (int i = 0; i < 1000; ++i) { Vector3D v = new Vector3D(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v))); } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) { Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v))); } else { Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v))); } } }
Example #23
Source File: SphericalPolygonsSetTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testEmpty() { SphericalPolygonsSet empty = (SphericalPolygonsSet) new RegionFactory<Sphere2D>().getComplement(new SphericalPolygonsSet(1.0e-10)); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, new Well1024a(0x76d9205d6167b6ddl)); for (int i = 0; i < 1000; ++i) { Vector3D v = new Vector3D(random.nextVector()); Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v))); } Assert.assertEquals(0, empty.getSize(), 1.0e-10); Assert.assertEquals(0, empty.getBoundarySize(), 1.0e-10); Assert.assertEquals(0, empty.getBoundaryLoops().size()); Assert.assertTrue(empty.getEnclosingCap().getRadius() < 0); Assert.assertTrue(Double.isInfinite(empty.getEnclosingCap().getRadius())); }
Example #24
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 5 votes |
@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 #25
Source File: SphericalPolygonsSetTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testFullSphere() { SphericalPolygonsSet full = new SphericalPolygonsSet(1.0e-10); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, new Well1024a(0x852fd2a0ed8d2f6dl)); for (int i = 0; i < 1000; ++i) { Vector3D v = new Vector3D(random.nextVector()); Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v))); } Assert.assertEquals(4 * FastMath.PI, new SphericalPolygonsSet(0.01, new S2Point[0]).getSize(), 1.0e-10); Assert.assertEquals(0, new SphericalPolygonsSet(0.01, new S2Point[0]).getBoundarySize(), 1.0e-10); Assert.assertEquals(0, full.getBoundaryLoops().size()); Assert.assertTrue(full.getEnclosingCap().getRadius() > 0); Assert.assertTrue(Double.isInfinite(full.getEnclosingCap().getRadius())); }
Example #26
Source File: SphericalPolygonsSetTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testSouthHemisphere() { double tol = 0.01; double sinTol = FastMath.sin(tol); SphericalPolygonsSet south = new SphericalPolygonsSet(Vector3D.MINUS_K, tol); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, new Well1024a(0x6b9d4a6ad90d7b0bl)); for (int i = 0; i < 1000; ++i) { Vector3D v = new Vector3D(random.nextVector()); if (v.getZ() < -sinTol) { Assert.assertEquals(Location.INSIDE, south.checkPoint(new S2Point(v))); } else if (v.getZ() > sinTol) { Assert.assertEquals(Location.OUTSIDE, south.checkPoint(new S2Point(v))); } else { Assert.assertEquals(Location.BOUNDARY, south.checkPoint(new S2Point(v))); } } Assert.assertEquals(1, south.getBoundaryLoops().size()); EnclosingBall<Sphere2D, S2Point> southCap = south.getEnclosingCap(); Assert.assertEquals(0.0, S2Point.MINUS_K.distance(southCap.getCenter()), 1.0e-10); Assert.assertEquals(0.5 * FastMath.PI, southCap.getRadius(), 1.0e-10); EnclosingBall<Sphere2D, S2Point> northCap = ((SphericalPolygonsSet) new RegionFactory<Sphere2D>().getComplement(south)).getEnclosingCap(); Assert.assertEquals(0.0, S2Point.PLUS_K.distance(northCap.getCenter()), 1.0e-10); Assert.assertEquals(0.5 * FastMath.PI, northCap.getRadius(), 1.0e-10); }
Example #27
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testSqueezedHexa() { PolygonsSet set = new PolygonsSet(1.0e-10, new Vector2D(-6, -4), new Vector2D(-8, -8), new Vector2D( 8, -8), new Vector2D( 6, -4), new Vector2D(10, 4), new Vector2D(-10, 4)); Assert.assertEquals(Location.OUTSIDE, set.checkPoint(new Vector2D(0, 6))); }
Example #28
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testSqueezedHexa() { PolygonsSet set = new PolygonsSet(1.0e-10, new Vector2D(-6, -4), new Vector2D(-8, -8), new Vector2D( 8, -8), new Vector2D( 6, -4), new Vector2D(10, 4), new Vector2D(-10, 4)); Assert.assertEquals(Location.OUTSIDE, set.checkPoint(new Vector2D(0, 6))); }
Example #29
Source File: ComponentInstanceStringConverter.java From AILibs with GNU Affero General Public License v3.0 | 5 votes |
private void resolveNumericParameter(final ComponentInstance componentInstance, final Parameter parameter, final String parameterName, final List<String> parameterRefinement) { ParameterRefinementConfiguration parameterRefinementConfiguration = this.componentParameters.get(componentInstance.getComponent()).get(parameter); NumericParameterDomain parameterDomain = ((NumericParameterDomain) parameter.getDefaultDomain()); Interval currentInterval = null; Interval nextInterval = new Interval(parameterDomain.getMin(), parameterDomain.getMax()); double parameterValue = Double.parseDouble(componentInstance.getParameterValues().get(parameterName)); double precision = parameterValue == 0 ? 0 : Math.ulp(parameterValue); while (true) { currentInterval = nextInterval; parameterRefinement.add(this.serializeInterval(currentInterval)); List<Interval> refinement = Util.getNumericParameterRefinement(nextInterval, parameterValue, parameterDomain.isInteger(), parameterRefinementConfiguration); if (refinement.isEmpty()) { break; } for (Interval interval : refinement) { if (interval.checkPoint(parameterValue, precision) == Location.INSIDE || interval.checkPoint(parameterValue, precision) == Location.BOUNDARY) { nextInterval = interval; break; } } } parameterRefinement.add(String.valueOf(parameterValue)); }
Example #30
Source File: PolygonsSetTest.java From astor with GNU General Public License v2.0 | 5 votes |
@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); }