Download the PHP package macocci7/php-math-vector without Composer

On this page you can find all versions of the php package macocci7/php-math-vector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-math-vector

PHP-Math-Vector

A math library for handling vectors.

1. Features

PHP-Math-Vector handles 2-dimensional vectors and 3-dimensional vectors.

PHP-Math-Vector can:

2. Contents

3. Requiremnets

4. Installation

5. Usage

5.1. Two-dimensional Vectors

To handle two-dimensional vectors, create instances of Vector2d class at first.

5.1.1. Instantiation

Vector2d class needs initialPoint and components as arguments.

Now, you can handle the two-dimensional vectors $a and $b.

5.1.2. Length (Magnitude)

To get the length (magnitude) of the vector, use length() or magnitude() methods.

Note: Actually, the length() method is an alias of the magnitude() method.

5.1.3. Components

To get components of the vector, use the components() method.

5.1.4. Initial and Terminal points

To get initial point or terminal poinnt, use the initialPoint() or terminalPoint() method.

5.1.5. Unit vector

To get unit vectors, use the unitVector() method.

This method returns a new vector, and the original vector remains in its original state.

5.1.6. Multiplying by a real number

To multiply the vector by a real number, use the multiply() method.

This method returns a new vector, and the original vector remains in its original state.

5.1.7. Adding two vectors

To perform (vector a) + (vector b), use the add() method of the former vector ($a in this case), and set the latter vector as a parameter of this method ($b in this case). This returns a new vector that has the initial point of the former vector and whose components are the sum of the components of both vectors.

The former vector ($a in this case) and the latter vector ($b in this case) remain in their original state.

5.1.8. Subtracting one vector from another

To perform (vector a) - (vector b), use the subtract() method of the former vector ($a in this case), and set the latter vector as a parameter of this method ($b in this case). This returns a new vector that has the initial point of the former vector and whose compoents are the components obtained by subtracting the latter vector from the former vector.

The former vector ($a in this case) and the latter vector ($b in this case) remain in their original state.

5.1.9. Dot product

To get the dot product of two vectors, use dotProduct() method.

The result is the same for the methods in either vector.

5.1.10. Cosine

To get the cosine of the angle between two vectors, use cos() method.

The result is the same for the methods in either vector.

If the argument is omitted, the cosine of the angle with the x-axis is returned.

5.1.11. Angle

To get the angle between two vectors, use degrees() or radian() method.

The result is the same for the methods in either vector.

If the argument is omitted, the angle made with the x-axis is returned.

5.1.12. Rotation

To get a rotated vector, use rotate() method.

Pass degrees to rotate as an argument.

5.2. Three-dimensional Vectors

To handle three-dimensional vectors, create instances of Vector3d class at first.

5.2.1 Instantiation

Vector3d class needs initialPoint and components as arguments.

Now, you can handle the three-dimensional vectors $a and $b.

5.2.2. Length (Magnitude)

To get the length (magnitude) of the vector, use length() or magnitude() methods.

Note: Actually, the length() method is an alias of the magnitude() method.

5.2.3. Components

To get components of the vector, use the components() method.

5.2.4. Initial and Terminal Points

To get initial point or terminal poinnt, use the initialPoint() or terminalPoint() methods.

5.2.5. Unit Vector

To get unit vectors, use the unitVector() method.

This method returns a new vector, and the original vector remains in its original state.

5.2.6. Multiplying by a real number

To multiply the vector by a real number, use the multiply() method.

This method returns a new vector, and the original vector remains in its original state.

5.2.7. Adding two vectors

To perform (vector a) + (vector b), use the add() method of the former vector ($a in this case), and set the latter vector as a parameter of this method ($b in this case).

This returns a new vector that has the initial point of the former vector and whose components are the sum of the components of both vectors.

The former vector ($a in this case) and the latter vector ($b in this case) remain in their original state.

5.2.8. Subtracting one vector from another

To perform (vector a) - (vector b), use the subtract() method of the former vector ($a in this case), and set the latter vector as a parameter of this method ($b in this case). This returns a new vector that has the initial point of the former vector and whose compoents are the components obtained by subtracting the latter vector from the former vector.

The former vector ($a in this case) and the latter vector ($b in this case) remain in their original state.

5.2.9. Dot product

To get the dot product of two vectors, use dotProduct() method.

The result is the same for the methods in either vector.

5.2.10. Cross product

To get the cross product of two vectors, use crossProduct() method.

The result is the same for the methods in either vector.

This method returns a new vector, and the both original vectors remain in their original state.

5.2.11. Cosine

To get the cosine of the angle between two vectors, use cos() method.

The result is the same for the methods in either vector.

If the argument is omitted, the cosine of the angle with the xy-plane is returned.

5.2.12. Angle

To get the angle between two vectors, use degrees() or radian() method.

The result is the same for the methods in either vector.

If the argument is omitted, the angle made with the xy-plane is returned.

5.2.13. Rotation

To get a rotated vector around a vector, use rotate() method.

Pass a vector of rotation axis, and degrees to rotate as an argument.

This method returns a new vector, and the both original vectors remain in their original state.

6. Examples

7. LICENSE

MIT


Copyright 2024 - 2025 macocci7.


All versions of php-math-vector with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package macocci7/php-math-vector contains the following files

Loading the files please wait ....