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 agents.anac.y2019.harddealer.math3.geometry;
|
---|
18 |
|
---|
19 | import java.text.NumberFormat;
|
---|
20 |
|
---|
21 | import agents.anac.y2019.harddealer.math3.exception.MathArithmeticException;
|
---|
22 |
|
---|
23 | /** This interface represents a generic vector in a vectorial space or a point in an affine space.
|
---|
24 | * @param <S> Type of the space.
|
---|
25 | * @see Space
|
---|
26 | * @see Point
|
---|
27 | * @since 3.0
|
---|
28 | */
|
---|
29 | public interface Vector<S extends Space> extends Point<S> {
|
---|
30 |
|
---|
31 | /** Get the null vector of the vectorial space or origin point of the affine space.
|
---|
32 | * @return null vector of the vectorial space or origin point of the affine space
|
---|
33 | */
|
---|
34 | Vector<S> getZero();
|
---|
35 |
|
---|
36 | /** Get the L<sub>1</sub> norm for the vector.
|
---|
37 | * @return L<sub>1</sub> norm for the vector
|
---|
38 | */
|
---|
39 | double getNorm1();
|
---|
40 |
|
---|
41 | /** Get the L<sub>2</sub> norm for the vector.
|
---|
42 | * @return Euclidean norm for the vector
|
---|
43 | */
|
---|
44 | double getNorm();
|
---|
45 |
|
---|
46 | /** Get the square of the norm for the vector.
|
---|
47 | * @return square of the Euclidean norm for the vector
|
---|
48 | */
|
---|
49 | double getNormSq();
|
---|
50 |
|
---|
51 | /** Get the L<sub>∞</sub> norm for the vector.
|
---|
52 | * @return L<sub>∞</sub> norm for the vector
|
---|
53 | */
|
---|
54 | double getNormInf();
|
---|
55 |
|
---|
56 | /** Add a vector to the instance.
|
---|
57 | * @param v vector to add
|
---|
58 | * @return a new vector
|
---|
59 | */
|
---|
60 | Vector<S> add(Vector<S> v);
|
---|
61 |
|
---|
62 | /** Add a scaled vector to the instance.
|
---|
63 | * @param factor scale factor to apply to v before adding it
|
---|
64 | * @param v vector to add
|
---|
65 | * @return a new vector
|
---|
66 | */
|
---|
67 | Vector<S> add(double factor, Vector<S> v);
|
---|
68 |
|
---|
69 | /** Subtract a vector from the instance.
|
---|
70 | * @param v vector to subtract
|
---|
71 | * @return a new vector
|
---|
72 | */
|
---|
73 | Vector<S> subtract(Vector<S> v);
|
---|
74 |
|
---|
75 | /** Subtract a scaled vector from the instance.
|
---|
76 | * @param factor scale factor to apply to v before subtracting it
|
---|
77 | * @param v vector to subtract
|
---|
78 | * @return a new vector
|
---|
79 | */
|
---|
80 | Vector<S> subtract(double factor, Vector<S> v);
|
---|
81 |
|
---|
82 | /** Get the opposite of the instance.
|
---|
83 | * @return a new vector which is opposite to the instance
|
---|
84 | */
|
---|
85 | Vector<S> negate();
|
---|
86 |
|
---|
87 | /** Get a normalized vector aligned with the instance.
|
---|
88 | * @return a new normalized vector
|
---|
89 | * @exception MathArithmeticException if the norm is zero
|
---|
90 | */
|
---|
91 | Vector<S> normalize() throws MathArithmeticException;
|
---|
92 |
|
---|
93 | /** Multiply the instance by a scalar.
|
---|
94 | * @param a scalar
|
---|
95 | * @return a new vector
|
---|
96 | */
|
---|
97 | Vector<S> scalarMultiply(double a);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Returns true if any coordinate of this vector is infinite and none are NaN;
|
---|
101 | * false otherwise
|
---|
102 | * @return true if any coordinate of this vector is infinite and none are NaN;
|
---|
103 | * false otherwise
|
---|
104 | */
|
---|
105 | boolean isInfinite();
|
---|
106 |
|
---|
107 | /** Compute the distance between the instance and another vector according to the L<sub>1</sub> norm.
|
---|
108 | * <p>Calling this method is equivalent to calling:
|
---|
109 | * <code>q.subtract(p).getNorm1()</code> except that no intermediate
|
---|
110 | * vector is built</p>
|
---|
111 | * @param v second vector
|
---|
112 | * @return the distance between the instance and p according to the L<sub>1</sub> norm
|
---|
113 | */
|
---|
114 | double distance1(Vector<S> v);
|
---|
115 |
|
---|
116 | /** Compute the distance between the instance and another vector according to the L<sub>2</sub> norm.
|
---|
117 | * <p>Calling this method is equivalent to calling:
|
---|
118 | * <code>q.subtract(p).getNorm()</code> except that no intermediate
|
---|
119 | * vector is built</p>
|
---|
120 | * @param v second vector
|
---|
121 | * @return the distance between the instance and p according to the L<sub>2</sub> norm
|
---|
122 | */
|
---|
123 | double distance(Vector<S> v);
|
---|
124 |
|
---|
125 | /** Compute the distance between the instance and another vector according to the L<sub>∞</sub> norm.
|
---|
126 | * <p>Calling this method is equivalent to calling:
|
---|
127 | * <code>q.subtract(p).getNormInf()</code> except that no intermediate
|
---|
128 | * vector is built</p>
|
---|
129 | * @param v second vector
|
---|
130 | * @return the distance between the instance and p according to the L<sub>∞</sub> norm
|
---|
131 | */
|
---|
132 | double distanceInf(Vector<S> v);
|
---|
133 |
|
---|
134 | /** Compute the square of the distance between the instance and another vector.
|
---|
135 | * <p>Calling this method is equivalent to calling:
|
---|
136 | * <code>q.subtract(p).getNormSq()</code> except that no intermediate
|
---|
137 | * vector is built</p>
|
---|
138 | * @param v second vector
|
---|
139 | * @return the square of the distance between the instance and p
|
---|
140 | */
|
---|
141 | double distanceSq(Vector<S> v);
|
---|
142 |
|
---|
143 | /** Compute the dot-product of the instance and another vector.
|
---|
144 | * @param v second vector
|
---|
145 | * @return the dot product this.v
|
---|
146 | */
|
---|
147 | double dotProduct(Vector<S> v);
|
---|
148 |
|
---|
149 | /** Get a string representation of this vector.
|
---|
150 | * @param format the custom format for components
|
---|
151 | * @return a string representation of this vector
|
---|
152 | */
|
---|
153 | String toString(final NumberFormat format);
|
---|
154 |
|
---|
155 | }
|
---|