Java Code Examples for org.apache.commons.math3.geometry.Vector#dotProduct()

The following examples show how to use org.apache.commons.math3.geometry.Vector#dotProduct() . 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: GeometryHullTool.java    From geowave with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the distance between two points and a given vertex
 *
 * @return array if doubles double[0] = length of the projection from start on the line containing
 *         the segment(start to end) double[1] = distance to the segment double[2] = distance to
 *         the line containing the segment(start to end)
 */
public static double[] calcDistanceSegment(
    final Coordinate start,
    final Coordinate end,
    final Coordinate point) {

  final Vector<Euclidean2D> vOne = new Vector2D(start.x, start.y);

  final Vector<Euclidean2D> vTwo = new Vector2D(end.x, end.y);

  final Vector<Euclidean2D> vVertex = new Vector2D(point.x, point.y);

  final Vector<Euclidean2D> E1 = vTwo.subtract(vOne);

  final Vector<Euclidean2D> E2 = vVertex.subtract(vOne);

  final double distOneTwo = E2.dotProduct(E1);
  final double lengthVOneSq = E1.getNormSq();
  final double projectionLength = distOneTwo / lengthVOneSq;
  final Vector<Euclidean2D> projection = E1.scalarMultiply(projectionLength).add(vOne);
  final double o =
      ((projectionLength < 0.0) ? vOne.distance(vVertex)
          : ((projectionLength > 1.0) ? vTwo.distance(vVertex) : vVertex.distance(projection)));

  return new double[] {projectionLength, o, vVertex.distance(projection)};
}
 
Example 2
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Transform a 3D space point into an in-plane point.
 * @param point point of the space (must be a {@link Vector3D
 * Vector3D} instance)
 * @return in-plane point (really a {@link
 * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance)
 * @see #toSpace
 */
public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
    return new Vector2D(point.dotProduct(u), point.dotProduct(v));
}
 
Example 3
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Get the offset (oriented distance) of a point.
 * <p>The offset is 0 if the point is on the underlying hyperplane,
 * it is positive if the point is on one particular side of the
 * hyperplane, and it is negative if the point is on the other side,
 * according to the hyperplane natural orientation.</p>
 * @param point point to check
 * @return offset of the point
 */
public double getOffset(final Vector<Euclidean3D> point) {
    return point.dotProduct(w) + originOffset;
}
 
Example 4
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Transform a 3D space point into an in-plane point.
 * @param point point of the space (must be a {@link Vector3D
 * Vector3D} instance)
 * @return in-plane point (really a {@link
 * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance)
 * @see #toSpace
 */
public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
    return new Vector2D(point.dotProduct(u), point.dotProduct(v));
}
 
Example 5
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Get the offset (oriented distance) of a point.
 * <p>The offset is 0 if the point is on the underlying hyperplane,
 * it is positive if the point is on one particular side of the
 * hyperplane, and it is negative if the point is on the other side,
 * according to the hyperplane natural orientation.</p>
 * @param point point to check
 * @return offset of the point
 */
public double getOffset(final Vector<Euclidean3D> point) {
    return point.dotProduct(w) + originOffset;
}
 
Example 6
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Transform a 3D space point into an in-plane point.
 * @param point point of the space (must be a {@link Vector3D
 * Vector3D} instance)
 * @return in-plane point (really a {@link
 * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance)
 * @see #toSpace
 */
public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
    return new Vector2D(point.dotProduct(u), point.dotProduct(v));
}
 
Example 7
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Get the offset (oriented distance) of a point.
 * <p>The offset is 0 if the point is on the underlying hyperplane,
 * it is positive if the point is on one particular side of the
 * hyperplane, and it is negative if the point is on the other side,
 * according to the hyperplane natural orientation.</p>
 * @param point point to check
 * @return offset of the point
 */
public double getOffset(final Vector<Euclidean3D> point) {
    return point.dotProduct(w) + originOffset;
}
 
Example 8
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Transform a 3D space point into an in-plane point.
 * @param point point of the space (must be a {@link Vector3D
 * Vector3D} instance)
 * @return in-plane point (really a {@link
 * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance)
 * @see #toSpace
 */
public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
    return new Vector2D(point.dotProduct(u), point.dotProduct(v));
}
 
Example 9
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Get the offset (oriented distance) of a point.
 * <p>The offset is 0 if the point is on the underlying hyperplane,
 * it is positive if the point is on one particular side of the
 * hyperplane, and it is negative if the point is on the other side,
 * according to the hyperplane natural orientation.</p>
 * @param point point to check
 * @return offset of the point
 */
public double getOffset(final Vector<Euclidean3D> point) {
    return point.dotProduct(w) + originOffset;
}
 
Example 10
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Transform a 3D space point into an in-plane point.
 * @param point point of the space (must be a {@link Vector3D
 * Vector3D} instance)
 * @return in-plane point (really a {@link
 * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance)
 * @see #toSpace
 */
public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
    return new Vector2D(point.dotProduct(u), point.dotProduct(v));
}
 
Example 11
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Get the offset (oriented distance) of a point.
 * <p>The offset is 0 if the point is on the underlying hyperplane,
 * it is positive if the point is on one particular side of the
 * hyperplane, and it is negative if the point is on the other side,
 * according to the hyperplane natural orientation.</p>
 * @param point point to check
 * @return offset of the point
 */
public double getOffset(final Vector<Euclidean3D> point) {
    return point.dotProduct(w) + originOffset;
}
 
Example 12
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Transform a 3D space point into an in-plane point.
 * @param point point of the space (must be a {@link Vector3D
 * Vector3D} instance)
 * @return in-plane point (really a {@link
 * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance)
 * @see #toSpace
 */
public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
    return new Vector2D(point.dotProduct(u), point.dotProduct(v));
}
 
Example 13
Source File: Plane.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Get the offset (oriented distance) of a point.
 * <p>The offset is 0 if the point is on the underlying hyperplane,
 * it is positive if the point is on one particular side of the
 * hyperplane, and it is negative if the point is on the other side,
 * according to the hyperplane natural orientation.</p>
 * @param point point to check
 * @return offset of the point
 */
public double getOffset(final Vector<Euclidean3D> point) {
    return point.dotProduct(w) + originOffset;
}