Class Vector3
- java.lang.Object
-
- com.actelion.research.chem.forcefield.mmff.Vector3
-
public class Vector3 extends java.lang.Object
The Vector3 class provides common vector operations used throughout the MMFF codebase. This is not supposed to be a comprehensive vector library; instead, only those functions which were needed have been implemented.
-
-
Constructor Summary
Constructors Constructor Description Vector3()
Constructs a new vector with default coordinates.Vector3(double[] pos, int offset)
Constructs a new vector from three consecutive doubles in a positions array.Vector3(double[] pos, int atom1, int atom2)
Constructs a new vector starting at atom1 position and ending at atom2 position.Vector3(double x, double y, double z)
Constructs a new vector with given x, y and z coordinates.Vector3(ExtendedMolecule mol, int atom)
Constructs a new vector from the x, y, z coordinates of an atom in a molecule.Vector3(ExtendedMolecule mol, int atom1, int atom2)
Constructs a vector that represents the line travelling from the position of atom1 to the position of atom2.Vector3(MMFFMolecule mol, int atom)
Constructs a new vector from the x, y, z coordinates of an atom in a molecule.Vector3(MMFFMolecule mol, int atom1, int atom2)
Constructs a vector that represents the line travelling from the position of atom1 to the position of atom2.Vector3(Vector3 that)
Copy constructor, copies the x,y,z coordinates from another vector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector3
add(Vector3 that)
Adds two vectors together by component.double
angle(Vector3 that)
Returns the angle between this vector and that vector.double
cosAngle(Vector3 that)
Returns the cosine of the angle between this vector and that vector.Vector3
cross(Vector3 that)
Computes the vector cross product between this vector and that vector.double
distance(Vector3 that)
Computes the euclidean distance between two Vector3s.double
dot(Vector3 that)
Computes the vector dot product between this vector and that vector.boolean
equals(java.lang.Object obj)
Checks for equality between two vectors.int
hashCode()
Returns the hashcode of this vector.double
length()
Returns the length (or magnitude) of this vector.Vector3
negate()
Returns this vector negated (signs swapped).Vector3
normalise()
Normalises a vector.Vector3
sub(Vector3 that)
Subtracts that vector from this vector by component.Vector3
to(Vector3 that)
Returns a vector that points from this vector to that vector.java.lang.String
toString()
Returns a string form of this vector.void
write(double[] pos, int offset)
Writes the contents of this vector to the specified positions in a positions array.
-
-
-
Constructor Detail
-
Vector3
public Vector3()
Constructs a new vector with default coordinates.
-
Vector3
public Vector3(double x, double y, double z)
Constructs a new vector with given x, y and z coordinates.- Parameters:
x
- X coordinate.y
- Y coordinate.z
- Z coordinate.
-
Vector3
public Vector3(Vector3 that)
Copy constructor, copies the x,y,z coordinates from another vector.
-
Vector3
public Vector3(MMFFMolecule mol, int atom)
Constructs a new vector from the x, y, z coordinates of an atom in a molecule.- Parameters:
mol
- The molecule that the atom is in.atom
- The atom index.
-
Vector3
public Vector3(ExtendedMolecule mol, int atom)
Constructs a new vector from the x, y, z coordinates of an atom in a molecule.- Parameters:
mol
- The molecule that the atom is in.atom
- The atom index.
-
Vector3
public Vector3(double[] pos, int offset)
Constructs a new vector from three consecutive doubles in a positions array.- Parameters:
pos
- The double array of position coordinates.offset
- Where in the array to fetch the values from.
-
Vector3
public Vector3(double[] pos, int atom1, int atom2)
Constructs a new vector starting at atom1 position and ending at atom2 position. The vector is constructed using point information from a position array.
-
Vector3
public Vector3(MMFFMolecule mol, int atom1, int atom2)
Constructs a vector that represents the line travelling from the position of atom1 to the position of atom2. The resultant vector points towards atom2 from atom1.- Parameters:
mol
- The molecule that the atoms are in.atom1
- The first atom and starting point of the line.atom2
- The second atom and the end point of the line.
-
Vector3
public Vector3(ExtendedMolecule mol, int atom1, int atom2)
Constructs a vector that represents the line travelling from the position of atom1 to the position of atom2. The resultant vector points towards atom2 from atom1.- Parameters:
mol
- The molecule that the atoms are in.atom1
- The first atom and starting point of the line.atom2
- The second atom and the end point of the line.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
Checks for equality between two vectors. Vectors are considered equal if each component value is equal to its corresponding component value. Doubleing point values are considered equal if their difference is below some tolerance value (set in TOL).- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The vector to compare this vector with.- Returns:
- True if they are equal, false otherwise.
-
hashCode
public int hashCode()
Returns the hashcode of this vector.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hashcode.
-
write
public void write(double[] pos, int offset)
Writes the contents of this vector to the specified positions in a positions array.- Parameters:
pos
- The positions array to write to.offset
- Where in the array to write to.
-
negate
public Vector3 negate()
Returns this vector negated (signs swapped).- Returns:
- The negated vector.
-
to
public Vector3 to(Vector3 that)
Returns a vector that points from this vector to that vector. The resultant vector will have a length equal to the distance between the two vectors and will have a direction pointing towards that vector.
-
length
public double length()
Returns the length (or magnitude) of this vector. This is the euclidean distance from this vector to the origin (A vector at x=0, y=0, z=0).- Returns:
- The length.
-
normalise
public Vector3 normalise()
Normalises a vector. If the vector to be normalised has length zero, then the zero vector is returned.- Returns:
- This vector normalised.
-
add
public Vector3 add(Vector3 that)
Adds two vectors together by component.- Parameters:
that
- The other vector.- Returns:
- The component sum of the two vectors.
-
sub
public Vector3 sub(Vector3 that)
Subtracts that vector from this vector by component.- Parameters:
that
- The other vector.- Returns:
- The component difference of the two vectors.
-
distance
public double distance(Vector3 that)
Computes the euclidean distance between two Vector3s.- Parameters:
that
- The other Vector3 to calculate the distance to.- Returns:
- The distance between the two vectors.
-
dot
public double dot(Vector3 that)
Computes the vector dot product between this vector and that vector.- Parameters:
that
- The other vector.- Returns:
- The dot product of the two vectors.
-
cross
public Vector3 cross(Vector3 that)
Computes the vector cross product between this vector and that vector.- Parameters:
that
- The other vector.- Returns:
- The cross product of the two vectors.
-
angle
public double angle(Vector3 that)
Returns the angle between this vector and that vector.- Parameters:
that
- The other vector.- Returns:
- The angle between the two vectors in radians.
-
cosAngle
public double cosAngle(Vector3 that)
Returns the cosine of the angle between this vector and that vector.- Parameters:
that
- The other vector.- Returns:
- The cosine of the angle between the two vectors in radians.
-
toString
public java.lang.String toString()
Returns a string form of this vector.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string form of the vector.
-
-