PHPackages                             macocci7/php-math-vector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. macocci7/php-math-vector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

macocci7/php-math-vector
========================

Math library of vector

0.0.5(5mo ago)011MITPHP

Since Jul 14Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/macocci7/PHP-Math-Vector)[ Packagist](https://packagist.org/packages/macocci7/php-math-vector)[ RSS](/packages/macocci7-php-math-vector/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (6)Used By (0)

PHP-Math-Vector
===============

[](#php-math-vector)

A math library for handling vectors.

1. Features
-----------

[](#1-features)

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

`PHP-Math-Vector` can:

- return the length (magnitude) of the vector
- return the unit vector
- return a vector multiplied by a real number
- add two vectors
- subtract one vector from another
- return the `dot product` of the two vectors
- return the `cross product` of the two vectors
- return the `cosine` of the angle between two vectors
- return the angle between two vectors in `degrees` or `radian`
- return the `initial point` or `terminal point`
- return a set of each component of x and y
- rotate the vector by a specified angle

2. Contents
-----------

[](#2-contents)

- [1. Features](#1-features)
- 2.Contents
- [3. Requirements](#3-requirements)
- [4. Installation](#4-installation)
- [5. Usage](#5-usage)
- [6. Examples](#6-examples)
- [7. LICENSE](#7-license)

3. Requiremnets
---------------

[](#3-requiremnets)

- PHP 8.1 or later
- Composer

4. Installation
---------------

[](#4-installation)

```
composer require macocci7/php-math-vector
```

5. Usage
--------

[](#5-usage)

### 5.1. Two-dimensional Vectors

[](#51-two-dimensional-vectors)

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

#### 5.1.1. Instantiation

[](#511-instantiation)

`Vector2d` class needs `initialPoint` and `components` as arguments.

```
