# API:IVector

From Wiketomica

API Home | Participants | API | Discussion | Demos | Downloads | Documentation | Contact Us | Acknowledgements |

# IVector

## Reason for existence

Vectors are used throughout off-lattice simulation programs for quantities such as positions, velocities and gradients. Simulation components should be able to pass around vector quantities to one another.

subclass: IVectorMutable

## Proposed Interface

interface IVector { /** * Dimension of the space occupied by the vector. Number of elements in the * vector. */ readonly attribute unsigned int D; /** * Assigns the components of this vector to the elements of the given array. * Does not check that array length is consistent with vector dimension. * Inverse of the E method. */ void assignTo(double[] array); /** * Returns true if all corresponding elements of this and the given vector * are equal; returns false otherwise. */ boolean equals(in IVector v); /** * Vector components corresponding to the given index. For example, * x-component is given for i = 0. If index exceeds dimension of vector, no * error is given and the last element of the vector is returned. */ double get(in int i); /** * Returns the square magnitude of this vector, e.g., x^2 + y^2 for D = 2. */ double squared(); /** * Returns true if all components of this vector are zero; false otherwise. */ boolean isZero(); /** * Returns the dot product of this vector with the given one. */ double dot(in IVector u); /** * Returns true if any element of the vector is not-a-number. */ boolean isNaN(); /** * Returns square of vector resulting from subtracting given vector * from this one. Neither vector is changed by this operation. */ double Mv1Squared(in IVector v1); /** * Normalizes this vector, so this.squared() == 1. Divides all * components by Math.sqrt(this.squared()). */ void normalize(); /** * Applies the given function to each element of the vector. */ void map(in IFunction f); }

## Use

We expect that the IAtom subinterfaces that correspond to atoms with positions or velocities would include a `getPosition`

method to return the vector position of an atom as a double array. The position of the atom could be changed by directly manipulating the elements of the array.

To change the size of the simulation box, the dimensions of the IBoundary could be set by passing a double array to a `setDimensions`

method.