Download the PHP package nubs/vectorix without Composer
On this page you can find all versions of the php package nubs/vectorix. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nubs/vectorix
More information about nubs/vectorix
Files in nubs/vectorix
Informations about the package vectorix
vectorix
A PHP vector library.
Requirements
This library requires PHP 5.6, or newer.
Installation
This package uses composer so you can just add
nubs/vectorix
as a dependency to your composer.json
file or execute the
following command:
Vector
The Vector
class represents an immutable Euclidean
vector and its associated
operations.
All operations on the vector will return a new vector with the results. For example,
The keys of a vector's components are preserved through operations. Because of this, vectors MUST have the same keys in order to use them together. For example,
Creating a Vector
Constructor
The primary method for creating a vector is, of course, the constructor. It takes an array of the components of the vector (e.g., x, y, and z components). Components can be integers, floats, or a combination thereof.
Null Vectors
When needing a null vector (a
vector with zero magnitude), this static method makes creating one easy. All
of its components will be initialized to the integer 0
.
Properties of a Vector
Components
The components
method returns the components of the vector with keys kept
intact.
Dimension
The dimension
of a vector is the number of components in it. This is also
referred to as "cardinality".
Length
The length
, or
magnitude of a
vector is the distance from the origin to the point described by the vector.
It is always returned as a floating point number.
Tests
Equality
The isEqual
method tests to see if the two vectors are equal. They are only
equal if their components are identical (including same keys).
Same Dimension
The isSameDimension
method tests to see if the two vectors both have the same
dimension.
Same Vector Space
The isSameVectorSpace
method tests to see if the two vectors both belong to
the same vector space.
The vector space is defined in this library by the dimension of the vectors, and the keys of the vectors' components.
Basic Operations
Addition
The add
method performs vector
addition.
The two vectors must belong to the same vector space.
The result is a new vector where each component is the sum of the corresponding components in the two vectors.
Subtraction
The subtract
method performs vector
subtraction.
The two vectors must belong to the same vector space.
The result is a new vector where each component is the difference of the corresponding components in the two vectors
Scalar Multiplication
The multiplyByScalar
function performs scalar
multiplication
of a vector with a scalar value.
The result is a new vector where each component is the multiplication of that component with the scalar value.
Scalar Division
The divideByScalar
function performs scalar division of a vector with a
scalar value. This is the same as multiplying the vector by 1 / scalarValue
.
Trying to divide by zero will throw an exception.
The result is a new vector where each component is the division of that component with the scalar value.
Dot Product
The dotProduct
method performs a dot
product between two vectors. The
two vectors must belong to the same vector space.
Cross Product
The crossProduct
method computes the cross
product between two
three-dimensional vectors. The resulting vector is perpendicular to the plane
containing the two vectors.
Other Operations
Normalization
The normalize
method returns the unit
vector with the same direction as
the original vector.
Projection
The projectOnto
method computes the vector
projection of one vector onto
another. The resulting vector will be colinear with $b
.
Scalar Triple Product
The scalarTripleProduct
method computes the scalar triple
product.
This value represents the volume of the parallelepiped defined by the three
vectors.
Vector Triple Product
The vectorTripleProduct
method computes the vector triple
product.
Angle Between Vectors
The angleBetween
method computes the angle between two vectors in radians.
License
vectorix is licensed under the MIT license. See LICENSE for the full license text.