PHPackages                             marcoconsiglio/trigonometry - 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. marcoconsiglio/trigonometry

Abandoned → [marcoconsiglio/goniometry](/?search=marcoconsiglio%2Fgoniometry)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

marcoconsiglio/trigonometry
===========================

A PHP support for angles and trigonometric functions.

v2.0.0(4y ago)080[1 issues](https://github.com/MarcoConsiglio/trigonometry/issues)UnlicensePHP

Since Dec 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MarcoConsiglio/trigonometry)[ Packagist](https://packagist.org/packages/marcoconsiglio/trigonometry)[ RSS](/packages/marcoconsiglio-trigonometry/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

trigonometry
============

[](#trigonometry)

[![GitHub](https://camo.githubusercontent.com/ed36e634db443d20759dd723a4d61c48827405e38915bdf5a8b45dd9c285d9fd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6172636f636f6e7369676c696f2f747269676f6e6f6d65747279)](https://camo.githubusercontent.com/ed36e634db443d20759dd723a4d61c48827405e38915bdf5a8b45dd9c285d9fd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6172636f636f6e7369676c696f2f747269676f6e6f6d65747279)

[![GitHub release (latest by date)](https://camo.githubusercontent.com/aeb7b46cae9281ce511aa13f75c32aaf1e82682a8dae108452fdc735a2924ff7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d6172636f636f6e7369676c696f2f747269676f6e6f6d65747279)](https://camo.githubusercontent.com/aeb7b46cae9281ce511aa13f75c32aaf1e82682a8dae108452fdc735a2924ff7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d6172636f636f6e7369676c696f2f747269676f6e6f6d65747279)

[ ![](https://camo.githubusercontent.com/89fce29e9b2b966ce72875514597edf0ba9a8ec83e9f049c0dea83778d38741a/68747470733a2f2f636f6465636f762e696f2f67682f4d6172636f436f6e7369676c696f2f747269676f6e6f6d657472792f6272616e63682f6465762f67726170682f62616467652e7376673f746f6b656e3d53595339434f5530585a)](https://codecov.io/gh/MarcoConsiglio/trigonometry)
Mutation testing
[![MSI](https://camo.githubusercontent.com/44de195f0fa3318c563c1604a2d3695954524d09e35c2164ecdfc6adeadfcc53/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d75746174696f6e7325323053636f7265253230496e64696361746f722d38322532352d677265656e)](https://camo.githubusercontent.com/44de195f0fa3318c563c1604a2d3695954524d09e35c2164ecdfc6adeadfcc53/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d75746174696f6e7325323053636f7265253230496e64696361746f722d38322532352d677265656e)[![MCC](https://camo.githubusercontent.com/c7c1d7e76fe0bc898d89208fb55a9cba15f36ad31ba125a8a91a26a2f7d46c02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d75746174696f6e253230436f6465253230436f7665726167652d39382532352d627269676874677265656e)](https://camo.githubusercontent.com/c7c1d7e76fe0bc898d89208fb55a9cba15f36ad31ba125a8a91a26a2f7d46c02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d75746174696f6e253230436f6465253230436f7665726167652d39382532352d627269676874677265656e)[![CC MSI](https://camo.githubusercontent.com/4ba1d3f201a1df64afdb11dc08facba21eaf772161fbd627a4047c9c35afa71e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726564253230436f64652532304d53492d38332532352d677265656e)](https://camo.githubusercontent.com/4ba1d3f201a1df64afdb11dc08facba21eaf772161fbd627a4047c9c35afa71e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726564253230436f64652532304d53492d38332532352d677265656e)

A PHP support for angles.

Installation
============

[](#installation)

`composer require marcoconsiglio/trigonometry`

Usage
=====

[](#usage)

Import this class to represent angles.

```
use MarcoConsiglio\Trigonometry\Angle;
```

Import this class to sum angles.

```
use MarcoConsiglio\Trigonometry\Operations\Sum;
```

Creating an angle
-----------------

[](#creating-an-angle)

### Degrees, minutes and seconds

[](#degrees-minutes-and-seconds)

This creates an angle from its values in degrees, minutes and seconds:

```
$alfa = Angle::createFromValues(180, 12, 43, Angle::CLOCKWISE); // 180° 12' 43"
$alfa = new Angle(new FromDegrees(180, 12, 43, Angle::CLOCKWISE))
```

### Parse a string

[](#parse-a-string)

This creates an angle from its textual representation:

```
$beta = Angle::createFromString("180° 12' 43\""); // Input from the user
$beta = new Angle(new FromString("180° 12' 43\""));
```

This is possible thank to the regular expression

```
Angle::ANGLE_REGEX;
```

The regex treat degrees and minutes as integer numbers, but seconds are treated as a float number.

### Decimal

[](#decimal)

This create an angle from its decimal representation:

```
$gamma = Angle::createFromDecimal(180.2119); // 180.2119°
$gamma = new Angle(new FromDecimal(180.2119));
```

### Radiant

[](#radiant)

This create an angle from its radiant representation:

```
$delta = Angle::createFromRadiant(3.1452910063); // deg2rad(180.2119°)
$delta = new Angle(FromRadiant(3.1452910063));
```

### Exceptions when creating an angle

[](#exceptions-when-creating-an-angle)

Creating an angle by values overflowing the maximum (+/-)360° throws the `AngleOverflowException`

Creating an angle by string overflowing the maximum (+/-)360° throws the `NoMatchException`

Getting angle values
--------------------

[](#getting-angle-values)

You can obtain degrees values separated in an array (simple by default, or associative):

```
$values = $alfa->getDegrees();
echo $values[0]; // Degrees
echo $values[1]; // Minutes
echo $values[2]; // Seconds
$values = $alfa->getDegrees(true);
echo $value['degrees'];
echo $value['minutes'];
echo $value['seconds'];
```

There is read-only properties too:

```
$alfa->degrees;   // 180
$alfa->minutes;   // 12
$alfa->seconds;   // 43
$alfa->direction; // Angle::CLOCKWISE (1)
```

You can cast the angle to decimal:

```
$alfa->toDecimal(); // 180.2119
```

You can cast the angle to radiant:

```
$alfa->toRadiant(); // 3.1452910063
```

Negative angles
---------------

[](#negative-angles)

You can create negative angles too!

```
$alfa = Angle::createFromValues(180, 12, 43, Angle::COUNTER_CLOCKWISE);
$beta = Angle::createFromString("-180° 12' 43\"");
$gamma = Angle::createFromDecimal(-180.2119);
$delta = Angle::createFromRadiant(-3.1452910063);
```

Comparison
----------

[](#comparison)

You can compare an angle with a numeric value, numeric string or another `Angle` object.

### $\\alpha &amp;gt; \\beta$ (greater than)

[](#alpha--beta-greater-than)

```
$alfa = Angle::createFromDecimal(180);
$beta = Angle::createFromDecimal(90);
$gamma = Angle::createFromDecimal(360);
$alfa->isGreaterThan(90);       // true     180 >  90
$alfa->gt("90");                // true     180 >  90
$alfa->isGreaterThan($gamma);   // false    180 > 360
$alfa->gt($gamma);              // false    180 > 360
```

### $\\alpha \\ge \\beta$ (greater than or equal)

[](#alpha-ge-beta-greater-than-or-equal)

```
$alfa = Angle::createFromDecimal(180);
$beta = Angle::createFromDecimal(90);
$gamma = Angle::createFromDecimal(90);
$alfa->isGreaterThanOrEqual(90);        // true 180 >=  90
$alfa->gte("180");                      // true 180 >= 180
$beta->isGreaterThanOrEqual($gamma);    // true  90 >=  90
$beta->gte(90);                         // true  90 >=  90
```

### $\\alpha &amp;lt; \\beta$ (less than)

[](#alpha--beta-less-than)

```
$alfa = Angle::createFromDecimal(90);
$beta = Angle::createFromDecimal(180);
$alfa->isLessThan(180);     // true  90 < 180
$alfa->lt(180);             // true  90 < 180
$alfa->isLessThan($beta);   // true  90 < 180
$beta->lt($alfa);           // true 180 < 90
```

### $\\alpha \\le \\beta$ (less than or equal)

[](#alpha-le-beta-less-than-or-equal)

```
$alfa = Angle::createFromDecimal(90);
$beta = Angle::createFromDecimal(180);
$alfa->isLessThanOrEqual(180);      // true
$alfa->lte(90);                     // true
$alfa->isLessThanOrEqual($beta);    // true
$alfa->lte($beta);                  // true
```

### Direction

[](#direction)

Positive angle are represented by the class constant

```
Angle::CLOCKWISE; // 1
```

while negative angle are represented by the opposite class constant:

```
Angle::COUNTER_CLOCKWISE; // 1
```

You can toggle direction:

```
$alfa->toggleDirection();
```

You can check if an angle is clockwise or counterclockwise.

```
$alfa->isClockwise();           // false
$alfa->isCounterClockwise();    // true
```

Algebric sum between two angles
-------------------------------

[](#algebric-sum-between-two-angles)

The `Sum` class extends the `Angle` class, so you immediately obtain the algebric sum between two angles, passing in its constructor a FromAngles builder, which is a SumBuilder.

```
$alfa = Angle::createFromDecimal(180);
$beta = Angle::createFromDecimal(270);
$gamma = new Sum(new FromAngles($alfa, $beta));
(string) $gamma; // 90° 0' 0"
```

Note that if the sum is more than +360° or less than -360°, the resulting angle will be corrected to remain between these limits.

Code documentation
==================

[](#code-documentation)

UML Diagrams
------------

[](#uml-diagrams)

You can find a class diagram at `docs/classes.png`. [![UML class diagram](https://github.com/MarcoConsiglio/trigonometry/raw/dev/docs/classes.png)](https://github.com/MarcoConsiglio/trigonometry/blob/dev/docs/classes.png)

phpDoc
------

[](#phpdoc)

You can read the code documentation at `docs/index.html`.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

3

Last Release

1589d ago

Major Versions

v1.1.1 → v2.0.02022-01-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fb36102dfc597a74e864afc65952e328f158bff88f21ad993c1d79c51c80133?d=identicon)[MarcoConsiglio](/maintainers/MarcoConsiglio)

---

Top Contributors

[![MarcoConsiglio](https://avatars.githubusercontent.com/u/39809954?v=4)](https://github.com/MarcoConsiglio "MarcoConsiglio (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcoconsiglio-trigonometry/health.svg)

```
[![Health](https://phpackages.com/badges/marcoconsiglio-trigonometry/health.svg)](https://phpackages.com/packages/marcoconsiglio-trigonometry)
```

###  Alternatives

[elgentos/module-baseurlpath

Allow Magento config to have a base url path instead of root without moving Magento 2 into a subdirectory

104.9k](/packages/elgentos-module-baseurlpath)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
