Package org.opensourcephysics.numerics
Class VectorMath
java.lang.Object
org.opensourcephysics.numerics.VectorMath
VectorMath is a utility class for vector math.
Contains static methods for dot products, cross products, etc.
- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]
cross2D
(double[] v, double b) Calculates the cross product of a double[2] vector in a plane and a vector perpendicular to that plane.static double
cross2D
(double[] a, double[] b) Calculate the cross product of two-component vectors.static final double[]
cross3D
(double[] v1, double[] v2) Calculates the vector cross product of double[3] vectors v1 and v2.static double
dot
(double[] a, double[] b) Calculate the dot product of two vectors.static double
magnitude
(double[] a) Calculates the magnitude a vector.static double
magnitudeSquared
(double[] a) Computes the magnitdue squared of this vector.static double[]
normalize
(double[] a) static double[]
perp
(double[] a, double[] b) Computes the part of the first vector that is perpendicular to the second vector.static double[]
plus
(double[] a, double[] b) Add two vectors.static double[]
plus
(double[] a, double[] b, double c) Add a vector times a scalar to a vector.static double[]
project
(double[] a, double[] b) Projects the first vector onto the second vector.
-
Method Details
-
plus
public static double[] plus(double[] a, double[] b, double c) Add a vector times a scalar to a vector. Elements in the first vector are modified and set equal to the sum.- Parameters:
a
- the first vectorb
- the second vectorc
- the scalar multiplier- Returns:
- double[] the first vector.
-
plus
public static double[] plus(double[] a, double[] b) Add two vectors. Elements in the first vector are modified and set equal to the sum.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- double[] the first vector.
-
normalize
public static double[] normalize(double[] a) -
dot
public static double dot(double[] a, double[] b) Calculate the dot product of two vectors.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- the dot product
-
project
public static double[] project(double[] a, double[] b) Projects the first vector onto the second vector.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- the projection
-
perp
public static double[] perp(double[] a, double[] b) Computes the part of the first vector that is perpendicular to the second vector.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- the perpendicular part
-
magnitudeSquared
public static double magnitudeSquared(double[] a) Computes the magnitdue squared of this vector. The magnitude squared is dot product of a vector with itself.- Parameters:
a
- the vector- Returns:
- the magnitude squared
-
magnitude
public static double magnitude(double[] a) Calculates the magnitude a vector.- Parameters:
a
- the vector- Returns:
- the magnitude
-
cross3D
public static final double[] cross3D(double[] v1, double[] v2) Calculates the vector cross product of double[3] vectors v1 and v2.- Parameters:
v1
- the first vectorv2
- the second vector- Returns:
- double[] the 3D cross product
-
cross2D
public static double[] cross2D(double[] v, double b) Calculates the cross product of a double[2] vector in a plane and a vector perpendicular to that plane. Elements in the given vector are modified. The resulting vector componets are in the basis set of the given vector.- Parameters:
v
- the vector in the planeb
- the vector perpendicular to the plane- Returns:
- the cropss product
-
cross2D
public static double cross2D(double[] a, double[] b) Calculate the cross product of two-component vectors. The result is the component perpendicular to the plane.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- the cross product.
-