org.opensourcephysics.numerics

## Class VectorMath

• java.lang.Object
• org.opensourcephysics.numerics.VectorMath

• ```public final class VectorMath
extends java.lang.Object```
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

Methods
Modifier and Type Method and Description
`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.
`static double` ```cross2D(double[] a, double[] b)```
Calculate the cross product of two-component vectors.
`static 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)```
`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.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Method Detail

• #### 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 vector
`b` - the second vector
`c` - 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 vector
`b` - 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 vector
`b` - 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 vector
`b` - 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 vector
`b` - 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 vector
`v2` - 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 plane
`b` - 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 vector
`b` - the second vector
Returns:
the cross product.