MultiDimensionalEuclideanVector.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.geometry.euclidean;

  18. /**
  19.  * Abstract base class for Euclidean vectors with two or more dimensions.
  20.  *
  21.  * @param <V> Vector implementation type
  22.  */
  23. public abstract class MultiDimensionalEuclideanVector<V extends MultiDimensionalEuclideanVector<V>>
  24.         extends EuclideanVector<V> {
  25.     /** Get the projection of the instance onto the given base vector. The returned
  26.      * vector is parallel to {@code base}. Vector projection and rejection onto
  27.      * a given base are related by the equation
  28.      * <code>
  29.      *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
  30.      * </code>
  31.      * @param base base vector
  32.      * @return the vector projection of the instance onto {@code base}
  33.      * @exception IllegalArgumentException if the norm of the base vector is zero, NaN, or infinite
  34.      * @see #reject(MultiDimensionalEuclideanVector)
  35.      */
  36.     public abstract V project(V base);

  37.     /** Get the rejection of the instance from the given base vector. The returned
  38.      * vector is orthogonal to {@code base}. This operation can be interpreted as
  39.      * returning the orthogonal projection of the instance onto the hyperplane
  40.      * orthogonal to {@code base}. Vector projection and rejection onto
  41.      * a given base are related by the equation
  42.      * <code>
  43.      *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
  44.      * </code>
  45.      * @param base base vector
  46.      * @return the vector rejection of the instance from {@code base}
  47.      * @exception IllegalArgumentException if the norm of the base vector is zero, NaN, or infinite
  48.      * @see #project(MultiDimensionalEuclideanVector)
  49.      */
  50.     public abstract V reject(V base);

  51.     /** Get a unit vector orthogonal to the instance.
  52.      * @return a unit vector orthogonal to the current instance
  53.      * @throws IllegalArgumentException if the norm of the current instance is zero, NaN, or infinite
  54.      */
  55.     public abstract V orthogonal();

  56.     /** Get a unit vector orthogonal to the current vector and pointing in the direction
  57.      * of {@code dir}. This method is equivalent to calling {@code dir.reject(vec).normalize()}
  58.      * except that no intermediate vector object is produced.
  59.      * @param dir the direction to use for generating the orthogonal vector
  60.      * @return unit vector orthogonal to the current vector and pointing in the direction of
  61.      *      {@code dir} that does not lie along the current vector
  62.      * @throws IllegalArgumentException if either vector norm is zero, NaN or infinite, or the
  63.      *      given vector is collinear with this vector.
  64.      */
  65.     public abstract V orthogonal(V dir);
  66. }