Michael Thomas Flanagan's Java Scientific Library

VectorMaths Class:     Mathematical Vectors

     

Last update: 5 December 2011                                                                                                                              Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains the constructor and methods for creating and manipulating vectors in three dimensional Cartesian space:

A single point (final point) may be entered giving a vector from the Cartesian origin to that point. Two points may be entered giving a vector from the first (initial) to the second (final) point. Points may be entered as one, two or three dimensional points. A one dimensional point will be create a vector along the x-coordinate axis of three dimensional Cartesian space. A two dimensional point will create a vector lying in the x-y plane of three dimensional Cartesian space.

See Point for a convenient way of handling points in two and three dimensional space. Entering data to VectorMaths via an array of Point allows the entry of data types other than double. Point converts such arrays to double.

import directive: import flanagan.math.VectorMaths;

SUMMARY OF CONSTRUCTOR AND METHODS

Constructors public VectorMaths(double xCoordinate, double yCoordinate, double zCoordinate)
public VectorMaths(double xCoordinate, double yCoordinate)
public VectorMaths(double xCoordinate)
public VectorMaths(double[] coordinates2)
public VectorMaths(double[] coordinates1, double[] coordinates2)
public VectorMaths(Point coordinates2)
public VectorMaths(Point coordinates1, Point coordinates2)
Reset the coordinates public void setVector(double xCoordinate, double yCoordinate, double zCoordinate)
public void setVector(double xCoordinate, double yCoordinate)
public void setVector(double xCoordinate)
public void setVector(double[] coordinates2)
public void setVector(double[] coordinates1, double[] coordinates2)
public void setVector(Point coordinates2)
public void setVector(Point coordinates1, Point coordinates2)
Return the points public Point[] getVector()
public Point getInitialPoint()
public Point getFinalPoint()
public int getDimensionsEntered()
Deep copy public VectorMaths copy()
Addition public VectorMaths plus(VectorMaths vec2)
public static VectorMaths plus(VectorMaths vec1, VectorMaths vec2)
public void plusEquals(VectorMaths vec2)
Subtraction public VectorMaths minus(VectorMaths vec2)
public static VectorMaths minus(VectorMaths vec1, VectorMaths vec2)
public void minusEquals(VectorMaths vec2)
Multiplication by a scalar public VectorMaths times(double constant)
public static VectorMaths times(VectorMaths vec1, double constant)
public void timesEquals(double constant)
Dot Product public double dot(VectorMaths vec2)
public static double dot(VectorMaths vec1, VectorMaths vec2)
Cross Product public VectorMaths cross(VectorMaths vec2)
public static VectorMaths cross(VectorMaths vec1, VectorMaths vec2)
Length public double length()
public double magnitude()
public double norm()
Angle between two vectors public double angleDegrees(VectorMaths vec2)
public static VectorMaths angleDegrees(VectorMaths vec1, VectorMaths vec2)
public double angleRadians(VectorMaths vec2)
public static VectorMaths angleRadians(VectorMaths vec1, VectorMaths vec2)
Equality test public boolean isEqual(VectorMaths vec2)
public static boolean isEqual(VectorMaths vec1, VectorMaths vec2)
Convert to Phasor public Phasor toPhasor()



CONSTRUCTORS
public VectorMaths(double xCoordinate, double yCoordinate, double zCoordinate)
public VectorMaths(double xCoordinate, double yCoordinate)
public VectorMaths(double xCoordinate)
public VectorMaths(double[] coordinates2)
public VectorMaths(double[] coordinates1, double[] coordinates2)
public VectorMaths(Point coordinates2)
public VectorMaths(Point coordinates1, Point coordinates2)

Constructor with the final point entered as three cartesian coordinates
public VectorMaths(double xCoordinate, double yCoordinate, double zCoordinate)
Usage:                      VectorMaths vec = new VectorMaths(xcoord, ycoord, zcoord);
Creates an instance of VectorMaths representing a vector starting at the Cartesian origin and ending at the point, xcoord, ycoord, zcoord.

Constructor with the final point entered as two cartesian coordinates
public VectorMaths(double xCoordinate, double yCoordinate, double zCoordinate)
Usage:                      VectorMaths vec = new VectorMaths(xcoord, ycoord);
Creates an instance of VectorMaths representing a vector starting at the Cartesian origin and ending at the point, xcoord, ycoord, 0.0.

Constructor with the final point entered as a single cartesian coordinate
public VectorMaths(double xCoordinate)
Usage:                      VectorMaths vec = new VectorMaths(xcoord);
Creates an instance of VectorMaths representing a vector starting at the Cartesian origin and ending at the point, xcoord, 0.0, 0.0.

Constructor with the final point coordinates entered as an array of doubles
public VectorMaths(double[] coordinates2)
Usage:                      VectorMaths vec = new VectorMaths(coordinates);
Creates an instance of VectorMaths representing a vector starting at the Cartesian origin and ending at a point whose coordinates are suplied as the array of doubles, coordinates2. This array may be of length 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0.

Constructor with the initial and final point coordinates entered as arrays of doubles
public VectorMaths(double[] coordinates1, double[] coordinates2)
Usage:                      VectorMaths vec = new VectorMaths(coordinates1, coordinates2);
Creates an instance of VectorMaths representing a vector starting and ending at points whose coordinates are suplied as the array of doubles, coordinates1 and coordinates2. These arrays may be of length 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0. Both arrays must be of the same length.

Constructor with the final point coordinates entered as an instance of Point
public VectorMaths(double coordinates2)
Usage:                      VectorMaths vec = new VectorMaths(coordinates);
Creates an instance of VectorMaths representing a vector starting at the Cartesian origin and ending at a point whose coordinates are suplied as an instance of Point, coordinates2. This Point may be of dimension 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0.

Constructor with the initial and final point coordinates entered as instances of Point
public VectorMaths(Point coordinates1, Point coordinates2)
Usage:                      VectorMaths vec = new VectorMaths(coordinates1, coordinates2);
Creates an instance of VectorMaths representing a vector starting and ending at points whose coordinates are suplied as the instances of Point, coordinates1 and coordinates2. These arrays may be of length 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0. Both arrays must be of the same length.



METHODS

RESET THE COORDINATES
public void setVector(double xCoordinate, double yCoordinate, double zCoordinate)
public void setVector(double xCoordinate, double yCoordinate)
public void setVector(double xCoordinate)
public void setVector(double[] coordinates2)
public void setVector(double[] coordinates1, double[] coordinates2)
public void setVector(Point coordinates2)
public void setVector(Point coordinates1, Point coordinates2)

Reset with the final point entered as three cartesian coordinates
public void setVector(double xCoordinate, double yCoordinate, double zCoordinate)
Usage:                      vec.setVector(xcoord, ycoord, zcoord);
Resets the vector represented by the VectorMaths, vec, to a vector starting at the Cartesian origin and ending at the point, xcoord, ycoord, zcoord.

Reset with the final point entered as two cartesian coordinates
public void setVector(double xCoordinate, double yCoordinate, double zCoordinate)
Usage:                      vec.setVector(xcoord, ycoord);
Resets the vector represented by the VectorMaths, vec, to a vector starting at the Cartesian origin and ending at the point, xcoord, ycoord, 0.0.

Reset with the final point entered as a single cartesian coordinate
public void setVector(double xCoordinate)
Usage:                      vec.setVector(xcoord);
Resets the vector represented by the VectorMaths, vec, to a vector starting at the Cartesian origin and ending at the point, xcoord, 0.0, 0.0.

Reset with the final point coordinates entered as an array of doubles
public void setVector(double[] coordinates2)
Usage:                      vec.setVector(coordinates);
Resets the vector represented by the VectorMaths, vec, to a vector starting at the Cartesian origin and ending at a point whose coordinates are suplied as the array of doubles, coordinates2. This array may be of length 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0.

Reset with the initial and final point coordinates entered as arrays of doubles
public void setVector(double[] coordinates1, double[] coordinates2)
Usage:                      vec.setVector(coordinates1, coordinates2);
Resets the vector represented by the VectorMaths, vec, to a vector starting and ending at points whose coordinates are suplied as the array of doubles, coordinates1 and coordinates2. These arrays may be of length 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0. Both arrays must be of the same length.

Reset with the final point coordinates entered as an instance of Point
public void setVector(double coordinates2)
Usage:                      vec.setVector(coordinates);
Resets the vector represented by the VectorMaths, vec, to a vector starting at the Cartesian origin and ending at a point whose coordinates are suplied as an instance of Point, coordinates2. This Point may be of dimension 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0.

Reset with the initial and final point coordinates entered as instances of Point
public void setVector(Point coordinates1, Point coordinates2)
Usage:                      vec.setVector(coordinates1, coordinates2);
Resets the vector represented by the VectorMaths, vec, to a vector starting and ending at points whose coordinates are suplied as the instances of Point, coordinates1 and coordinates2. These arrays may be of length 1 (x-value), 2 (x-value and y-value) or 3 (x-value, y-value and z-value). Coordinate values that are not entered will be set to 0.0. Both arrays must be of the same length.



RETURN THE POINTS
public Point[] getVector()
public Point getInitialPoint()
public Point getFinalPoint()
public int getDimensionsEntered()

Return the initial and final points of the vector
public Point[] getVector()
Usage:                      points = vec.getVector();
Returns the initial and final point coordinates as a two dimensional array of Point, points. The element, points[0] corresponds to the initial point of the vector and points[1] corresponds to the final point of the vector.

Return the initial point of the vector
public Point[] getInitialPoint()
Usage:                      point0 = vec.getInitialPoint();
Returns the initial point coordinates as an instance of Point.

Return the final point of the vector
public Point[] getFinalPoint()
Usage:                      point1 = vec.getFinalPoint();
Returns the final point coordinates as an instance of Point.

Return the entered point dimensions
public int getDimensionsEntered()
Usage:                      nDimE = vec.getDimensionsEntered();
Returns the value of the point dimensions as entered. VectorMaths stores this value though al points are extended to three dimensions.



DEEP COPY
public VectorMaths copy()
Usage:                      copy = vec.copy();
Returns a deep copy.



ADDITION
public VectorMaths plus(VectorMaths vec2)
public static VectorMaths plus(VectorMaths vec1, VectorMaths vec2)
public void plusEquals(VectorMaths vec2)

Usage:                      vec12 = vec1.plus(vec2);
                                  vec12 = VectorMaths.plus(vec1, vec2);

Both the instance and static methods return a VectorMaths, vec12, representing a vector that is the sum of the vectors represented by the VectorMaths, vec1 and vec2.
[vec12 vector = vec2 vector + vec1 vector].

Usage:                      vec1.plusEquals(vec2);
This methods converts the vector represented by, vec1, to a vector that is the sum of this vector and the vector represented by vec2 and this sum of vectors is stored within vec1.
[vec1 vector = vec2 vector + vec1 vector].



SUBTRACTION
public VectorMaths minus(VectorMaths vec2)
public static VectorMaths minus(VectorMaths vec1, VectorMaths vec2)
public void minusEquals(VectorMaths vec2)

Usage:                      vec12 = vec1.minus(vec2);
                                  vec12 = VectorMaths.minus(vec1, vec2);

Both the instance and static methods return a VectorMaths, vec12, representing a vector that is the difference between the vectors represented by the VectorMaths, vec1 and vec2.
[vec12 vector = vec2 vector − vec1 vector].

Usage:                      vec1.minusEquals(vec2);
This methods converts the vector represented by, vec1, to a vector that is the difference between this vector and the vector represented by vec2 and this sum of vectors is stored within vec1.
[vec1 vector = vec2 vector − vec1 vector].



MULTIPLICATION BY A SCALAR
public VectorMaths times(double constant)
public static VectorMaths times(VectorMaths vec1, double constant)
public void timesEquals(double constant)

Usage:                      vecc = vec.times(constant);
                                  vecc = VectorMaths.times(vec, const);

Both the instance and static methods return a VectorMaths, vecc, representing a vector that is the vector represented by vec multiplied by a constant, const.

Usage:                      vec.timesEquals(const);
This methods converts the vector represented by, vec, to a vector that is the vector represented by vec multiplied by a constant, const, and this sum of vectors is stored within vec.



DOT PRODUCT
public double dot(VectorMaths vec2)
public static double dot(VectorMaths vec1, VectorMaths vec2)

Usage:                      dotProduct = vec1.dot(vec2);
                                  dotProduct = VectorMaths.dot(vec1, vec2);

Both the instance and static methods return the dot product, as a double, of the the two vectors represented by vec1 and vec2.



CROSS PRODUCT
public VectorMaths cross(VectorMaths vec2)
public static VectorMaths cross(VectorMaths vec1, VectorMaths vec2)

Usage:                      crossProduct = vec1.cross(vec2);
                                  crossProduct = VectorMaths.dot(vec1, vec2);

Both the instance and static methods return the cross product, represented as a VectorMaths instance, of the the two vectors represented by vec1 and vec2.



VECTOR LENGTH
public double length()
public double magnitude()
public double norm()

Usage:                      len = vec.length();
                                  len = vec.magnitude();
                                  len = vec.norm();

All three methods return the length
      
where x, y and z are the cartesian coordinates of the initial point of the vector (sub-script 0) and of the final point of the vector (sub-script 1) represented by vec.



ANGLE BETWEEN TWO VECTORS
public double angleDegrees(VectorMaths vec2)
public static VectorMaths angleDegrees(VectorMaths vec1, VectorMaths vec2)
public double angleRadians(VectorMaths vec2)
public static VectorMaths angleRadians(VectorMaths vec1, VectorMaths vec2)

Return angle in degrees
Usage:                      angledeg = vec1.angleDegrees(vec2);
                                  angledeg = VectorMaths.angleDegrees(vec1, vec2);

Both the instance and static methods return the angle, in degrees, between the two vectors represented by vec1 and vec2.

Return angle in radians
Usage:                      anglerad = vec1.angleRadians(vec2);
                                  anglerad = VectorMaths.angleRadians(vec1, vec2);

Both the instance and static methods return the angle, in radians, between the two vectors represented by vec1 and vec2.



Return angle in degrees
Usage:                      test = vec1.isEqual(vec2);
                                  test = VectorMaths.isEqual(vec1, vec2);

Both the instance and static methods return true if the VectorMaths instances, vec1 and vec2, are identical and return false if they are not.



CONVERT TO Phasor
public Phasor toPhasor()

Usage:                      ph = vec.toPhasor();
This method converts the vector, represented by vec, to its phasor form and returns this as an instance of Phasor, ph.


OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:


This page was prepared by Dr Michael Thomas Flanagan