edu.sdsc.mbt.util
Class Algebra

java.lang.Object
  extended byedu.sdsc.mbt.util.Algebra

public class Algebra
extends java.lang.Object

This class provides a number of algebreic methods for computing various distances and angles between 3D virtex coordinates (double[3]).

Author:
John L. Moreland
See Also:
Bond, BondFactory

Field Summary
static int X_AXIS
           
static int Y_AXIS
           
static int Z_AXIS
           
 
Constructor Summary
Algebra()
           
 
Method Summary
static double angle(double[] v1, double[] v2, double[] v3)
          Calculate the angle formed by three virtex coordinates.
static void angleAxisRotate(double[] angleAxis, double[] point)
          Rotate the point by the given angle-axis {angle,x,y,z} rotation vector.
static double[] crossProduct(double[] v1, double[] v2)
           
static void crossProduct(double[] v1, double[] v2, double[] result)
          Compute the vector cross product between v1 and v2 storing the output in result.
static void crossProduct(float[] v1, float[] v2, float[] result)
           
static double dihedralAngle(double[] v1, double[] v2, double[] v3, double[] v4)
          Calculate the dihedral angle defined by four virtex coordinates.
static double distance(double[] v1, double[] v2)
          Compute the distance between two virtex coordinates.
static double distance(Vec3d v1, Vec3d v2)
          Compute the distance between coordinates using double values
static float distance(Vec3f v1, Vec3f v2)
          Compute the distance between coordinates using float values
static double dotProduct(double[] v1, double[] v2)
          Return the vector dot product between v1 and v2.
static float dotProduct(float[] v1, float[] v2)
           
static double getAngle(Vec3d v2, Vec3d v1, Vec3d v3)
          Calculates the angle formed by the three points.
static double getAngleBetweenVectors(double[] a, double[] b)
           
static Vec3d getAtomCoordinates(Atom atom)
          Returns coordinates of the given Atom in 3d space.
static double getDihedralAngle(Vec3d v3, Vec3d v1, Vec3d v2, Vec3d v4)
          Calculates the dihedral angle defined by four points
static double[][] getInverseMatrix(double[][] a)
           
static double[] getNormalizedVector(double[] inVector)
           
static double[] getNormalizedVector(double[] start, double[] end)
           
static double[] getReverseVector(double[] vector)
           
static double[] getVector(double[] start, double[] end)
           
static double[] getVectorDifference(double[] vector1, double[] vector2)
          subtract function
static double[] getVectorSum(double[] vector1, double[] vector2)
           
static double[] getViewPoint(double[] target, double distance)
          Calculate the position of the view point on Z axis, given the center of the viewed structure and the required distance
static void main(java.lang.String[] args)
           
static void matrixRotate(double[] matrix, double[] point)
          Rotate the point by the given 16-element rotation matrix.
static Vec3d midpoint(Vec3d a, Vec3d b)
          Compute the midpoint between two points.
static double[] multiplyMatrices(double[][] a, double[][] b)
           
static double[] multiplySquareMatrices(double[] a, double[] b)
          Calculate a product of two matrices and return the result
static void normalizeVector(double[] vector)
          Compute the normalized vector in place.
static void normalizeVector(double[] inVector, double[] outVector)
          Compute the normalized inVector storing the result in outVector.
static void normalizeVector(float[] vector)
           
static void normalizeVector(float[] inVector, float[] outVector)
           
static void orthogonalize(float[] vector1, float[] vector2)
          Orthogonalize one vector to another.
static void reverseVector(double[] vector)
           
static void rotationToMatrix(double[] rotation, double[] matrix)
          Convert the angle-axis {angle,x,y,z} rotation vector to a 16-element rotation matrix.
static void scalarMultiply(double[] vector, double scalar)
          Multiply a vector times a scalar.
static void scalarMultiply(float[] vector, float scalar)
          Multiply a vector times a scalar.
static void setVectorLength(double[] vector, double length)
           
static double[] solveSystemOfEquations(double[] system)
          This method solves a system of three equations with three unknowns and returns an array of x,y,z values
static void subtractVectors(double[] vector1, double[] vector2)
          Subtract one vector from another.
static void subtractVectors(float[] vector1, float[] vector2)
          Subtract one vector from another.
static double vectorLength(double[] vector)
          Return the cartesian length of the vector.
static float vectorLength(float[] vector)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

X_AXIS

public static final int X_AXIS
See Also:
Constant Field Values

Y_AXIS

public static final int Y_AXIS
See Also:
Constant Field Values

Z_AXIS

public static final int Z_AXIS
See Also:
Constant Field Values
Constructor Detail

Algebra

public Algebra()
Method Detail

distance

public static double distance(double[] v1,
                              double[] v2)
Compute the distance between two virtex coordinates.

  v1--v2
  

Parameters:
v1 - First virtex coordinate as double[3].
v2 - Second virtex coordinate as double[3].
Returns:
the computed distence.

angle

public static double angle(double[] v1,
                           double[] v2,
                           double[] v3)
Calculate the angle formed by three virtex coordinates.

  v1  v3
   \  /
    v2
  

Parameters:
v1 - An end virtex coordinate as double[3].
v2 - The middle virtex coordinate as double[3].
v3 - An end virtex coordinate as double[3].
Returns:
angle in degrees.

dihedralAngle

public static double dihedralAngle(double[] v1,
                                   double[] v2,
                                   double[] v3,
                                   double[] v4)
Calculate the dihedral angle defined by four virtex coordinates.

  v1     v4
   \     /
    v2--v3
  

Parameters:
v1 - An end virtex coordinate as double[3].
v2 - An interior virtex coordinate as double[3].
v3 - An interior virtex coordinate as double[3].
v4 - An end virtex coordinate as double[3].
Returns:
dihedral angle in degrees.

midpoint

public static Vec3d midpoint(Vec3d a,
                             Vec3d b)
Compute the midpoint between two points.


distance

public static double distance(Vec3d v1,
                              Vec3d v2)
Compute the distance between coordinates using double values


distance

public static float distance(Vec3f v1,
                             Vec3f v2)
Compute the distance between coordinates using float values


getAtomCoordinates

public static Vec3d getAtomCoordinates(Atom atom)
Returns coordinates of the given Atom in 3d space.

Parameters:
atom -
Returns:

getAngle

public static double getAngle(Vec3d v2,
                              Vec3d v1,
                              Vec3d v3)
Calculates the angle formed by the three points.

Parameters:
v2 - coordinates of the middle point
v1 - coordinates of an end point
v3 - coordinates of an end point
Returns:
angle in degrees

getDihedralAngle

public static double getDihedralAngle(Vec3d v3,
                                      Vec3d v1,
                                      Vec3d v2,
                                      Vec3d v4)
Calculates the dihedral angle defined by four points

Parameters:
v3 - coordinates of an end point
v1 - coordinates of the second point in the sequence
v2 - coordinates of the third point
v4 - coordinates of the other end point
Returns:

crossProduct

public static void crossProduct(double[] v1,
                                double[] v2,
                                double[] result)
Compute the vector cross product between v1 and v2 storing the output in result.

Parameters:
v1 - First vector argument.
v2 - Second vector argument.
result - The vector in which the result will be stored.

crossProduct

public static void crossProduct(float[] v1,
                                float[] v2,
                                float[] result)

crossProduct

public static double[] crossProduct(double[] v1,
                                    double[] v2)

dotProduct

public static double dotProduct(double[] v1,
                                double[] v2)
Return the vector dot product between v1 and v2.

Parameters:
v1 - First vector argument.
v2 - Second vector argument.
Returns:
The dot product value.

dotProduct

public static float dotProduct(float[] v1,
                               float[] v2)

normalizeVector

public static void normalizeVector(double[] inVector,
                                   double[] outVector)
Compute the normalized inVector storing the result in outVector. Note: it is safe to pass the same object for in and out vectors.

Parameters:
inVector - The input vector argument.
outVector - The output vector.

getNormalizedVector

public static double[] getNormalizedVector(double[] inVector)

normalizeVector

public static void normalizeVector(double[] vector)
Compute the normalized vector in place.

Parameters:
vector - The vector to be normalized in-place.

normalizeVector

public static void normalizeVector(float[] vector)

normalizeVector

public static void normalizeVector(float[] inVector,
                                   float[] outVector)

vectorLength

public static float vectorLength(float[] vector)

vectorLength

public static double vectorLength(double[] vector)
Return the cartesian length of the vector.

Parameters:
vector - The input vector.
Returns:
The length of the input vector.

reverseVector

public static void reverseVector(double[] vector)

getReverseVector

public static double[] getReverseVector(double[] vector)

setVectorLength

public static void setVectorLength(double[] vector,
                                   double length)

angleAxisRotate

public static void angleAxisRotate(double[] angleAxis,
                                   double[] point)
Rotate the point by the given angle-axis {angle,x,y,z} rotation vector.

Parameters:
angleAxis - The angle-axis rotation vector.
point - The point to be rotated in-place.

matrixRotate

public static void matrixRotate(double[] matrix,
                                double[] point)
Rotate the point by the given 16-element rotation matrix.

Parameters:
matrix - The 16-element rotation matrix.
point - The point to be rotated in-place.

rotationToMatrix

public static void rotationToMatrix(double[] rotation,
                                    double[] matrix)
Convert the angle-axis {angle,x,y,z} rotation vector to a 16-element rotation matrix.

Parameters:
rotation - The angle-axis rotation vector.
matrix - The resulting 16-element rotation matrix.

getViewPoint

public static double[] getViewPoint(double[] target,
                                    double distance)
Calculate the position of the view point on Z axis, given the center of the viewed structure and the required distance

Parameters:
target -
distance -
Returns:

multiplyMatrices

public static double[] multiplyMatrices(double[][] a,
                                        double[][] b)

multiplySquareMatrices

public static double[] multiplySquareMatrices(double[] a,
                                              double[] b)
Calculate a product of two matrices and return the result

Returns:
result

solveSystemOfEquations

public static double[] solveSystemOfEquations(double[] system)
This method solves a system of three equations with three unknowns and returns an array of x,y,z values

Parameters:
system - linear array of all 12 constituents: a1, b1, c1, d1, a2, b2.. etc
Returns:

getAngleBetweenVectors

public static double getAngleBetweenVectors(double[] a,
                                            double[] b)

getVector

public static double[] getVector(double[] start,
                                 double[] end)

getNormalizedVector

public static double[] getNormalizedVector(double[] start,
                                           double[] end)

main

public static void main(java.lang.String[] args)

getInverseMatrix

public static double[][] getInverseMatrix(double[][] a)

scalarMultiply

public static void scalarMultiply(float[] vector,
                                  float scalar)
Multiply a vector times a scalar.

Parameters:
vector - The vector to be scaled in-place.

scalarMultiply

public static void scalarMultiply(double[] vector,
                                  double scalar)
Multiply a vector times a scalar.

Parameters:
vector - The vector to be scaled in-place.

orthogonalize

public static void orthogonalize(float[] vector1,
                                 float[] vector2)
Orthogonalize one vector to another.

Parameters:
vector1 - The vector to be orthogonalized.
vector2 - The reference vector for orthogonalization.
Throws:
java.lang.NullPointerException - for null vector.
java.lang.IllegalArgumentException - for zero vector.

subtractVectors

public static void subtractVectors(double[] vector1,
                                   double[] vector2)
Subtract one vector from another.

Parameters:
vector1 - The vector to be modified.
vector2 - The vector to subtract.

subtractVectors

public static void subtractVectors(float[] vector1,
                                   float[] vector2)
Subtract one vector from another.

Parameters:
vector1 - The vector to be modified.
vector2 - The vector to subtract.

getVectorDifference

public static double[] getVectorDifference(double[] vector1,
                                           double[] vector2)
subtract function

Parameters:
vector1 -
vector2 -
Returns:

getVectorSum

public static double[] getVectorSum(double[] vector1,
                                    double[] vector2)