Java Code Examples for org.apache.commons.math3.geometry.partitioning.Region.Location#OUTSIDE

The following examples show how to use org.apache.commons.math3.geometry.partitioning.Region.Location#OUTSIDE . 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 vote down vote up
/** 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 2
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** 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 3
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** 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 4
Source File: Math_4_SubLine_s.java    From coming with MIT License 6 votes vote down vote up
/** 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 5
Source File: SubLine_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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) {//Math-4
		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_s.java    From coming with MIT License 6 votes vote down vote up
/** 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 7
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** 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 vote down vote up
/** 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 vote down vote up
/** 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: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** 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 11
Source File: Interval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check a point with respect to the interval.
 * @param point point to check
 * @param tolerance tolerance below which points are considered to
 * belong to the boundary
 * @return a code representing the point status: either {@link
 * Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
 * @since 3.1
 */
public Location checkPoint(final double point, final double tolerance) {
    if (point < lower - tolerance || point > upper + tolerance) {
        return Location.OUTSIDE;
    } else if (point > lower + tolerance && point < upper - tolerance) {
        return Location.INSIDE;
    } else {
        return Location.BOUNDARY;
    }
}
 
Example 12
Source File: Interval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check a point with respect to the interval.
 * @param point point to check
 * @param tolerance tolerance below which points are considered to
 * belong to the boundary
 * @return a code representing the point status: either {@link
 * Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
 * @since 3.1
 */
public Location checkPoint(final double point, final double tolerance) {
    if (point < lower - tolerance || point > upper + tolerance) {
        return Location.OUTSIDE;
    } else if (point > lower + tolerance && point < upper - tolerance) {
        return Location.INSIDE;
    } else {
        return Location.BOUNDARY;
    }
}
 
Example 13
Source File: Interval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check a point with respect to the interval.
 * @param point point to check
 * @param tolerance tolerance below which points are considered to
 * belong to the boundary
 * @return a code representing the point status: either {@link
 * Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
 * @since 3.1
 */
public Location checkPoint(final double point, final double tolerance) {
    if (point < lower - tolerance || point > upper + tolerance) {
        return Location.OUTSIDE;
    } else if (point > lower + tolerance && point < upper - tolerance) {
        return Location.INSIDE;
    } else {
        return Location.BOUNDARY;
    }
}
 
Example 14
Source File: RegionFactory.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public BSPTree<S> fixNode(final BSPTree<S> node) {
    // get a representative point in the degenerate cell
    final BSPTree<S> cell = node.pruneAroundConvexCell(Boolean.TRUE, Boolean.FALSE, null);
    final Region<S> r = region1.buildNew(cell);
    final Point<S> p = r.getBarycenter();
    return new BSPTree<S>(region1.checkPoint(p) == Location.INSIDE &&
                          region2.checkPoint(p) == Location.OUTSIDE);
}
 
Example 15
Source File: BoundaryProjector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check if a projected point lies on a boundary part.
 * @param point projected point to check
 * @param hyperplane hyperplane into which the point was projected
 * @param part boundary part
 * @return true if point lies on the boundary part
 */
private boolean belongsToPart(final Point<S> point, final Hyperplane<S> hyperplane,
                              final Region<T> part) {

    // there is a non-null sub-space, we can dive into smaller dimensions
    @SuppressWarnings("unchecked")
    final Embedding<S, T> embedding = (Embedding<S, T>) hyperplane;
    return part.checkPoint(embedding.toSubSpace(point)) != Location.OUTSIDE;

}
 
Example 16
Source File: DiscretizationHelper.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Discretizes the particular provided value. Discretization in this case means
 * to replace the original value by a categorical value. The categorical value
 * is simply the index of the interval the value was assigned to.
 *
 * @param value
 *            The (numeric) value to be discretized
 * @param policy
 *            The policy that has to be used for discretization
 * @return
 */
protected int discretize(final double value, final AttributeDiscretizationPolicy policy) {
	List<Interval> intervals = policy.getIntervals();
	// Find the interval to which the value belongs
	for (Interval i : intervals) {
		if (i.checkPoint(value, 0) != Location.OUTSIDE) {
			return intervals.indexOf(i);
		}
	}

	throw new IllegalStateException(String.format("Policy does not cover value %f", value));
}
 
Example 17
Source File: BoundaryProjector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check if a projected point lies on a boundary part.
 * @param point projected point to check
 * @param hyperplane hyperplane into which the point was projected
 * @param part boundary part
 * @return true if point lies on the boundary part
 */
private boolean belongsToPart(final Point<S> point, final Hyperplane<S> hyperplane,
                              final Region<T> part) {

    // there is a non-null sub-space, we can dive into smaller dimensions
    @SuppressWarnings("unchecked")
    final Embedding<S, T> embedding = (Embedding<S, T>) hyperplane;
    return part.checkPoint(embedding.toSubSpace(point)) != Location.OUTSIDE;

}
 
Example 18
Source File: RegionFactory.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public BSPTree<S> fixNode(final BSPTree<S> node) {
    // get a representative point in the degenerate cell
    final BSPTree<S> cell = node.pruneAroundConvexCell(Boolean.TRUE, Boolean.FALSE, null);
    final Region<S> r = region1.buildNew(cell);
    final Point<S> p = r.getBarycenter();
    return new BSPTree<S>(region1.checkPoint(p) == Location.INSIDE &&
                          region2.checkPoint(p) == Location.OUTSIDE);
}
 
Example 19
Source File: Arc.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check a point with respect to the arc.
 * @param point point to check
 * @return a code representing the point status: either {@link
 * Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
 */
public Location checkPoint(final double point) {
    final double normalizedPoint = MathUtils.normalizeAngle(point, middle);
    if (normalizedPoint < lower - tolerance || normalizedPoint > upper + tolerance) {
        return Location.OUTSIDE;
    } else if (normalizedPoint > lower + tolerance && normalizedPoint < upper - tolerance) {
        return Location.INSIDE;
    } else {
        return (getSize() >= MathUtils.TWO_PI - tolerance) ? Location.INSIDE : Location.BOUNDARY;
    }
}
 
Example 20
Source File: NPEfix15_fifteen_s.java    From coming with MIT License 5 votes vote down vote up
/** 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);
//        FIX
//        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;
        }

    }