Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Planar angle mathematics library for Python.

Project description

Downloads Latest Version Development Status Supported Python Versions License

Planar angle mathematics library for Python.

This library contains many different functions for converting between units, comparing angles, and doing angle arithmetic.


Quickstart: pip3 install anglr.


Consider the following trivial angle comparison code:

import math
heading = get_compass_value() # angle in radians normalized to $[0, 2*pi)$
if target - math.pi / 4 <= heading <= target + math.pi / 4:
    print("Facing the target")
    print("Not facing the target")

Angle code is everywhere. The above is totally, utterly wrong (consider what happens when target is 0), yet this could easily be overlooked while writing and during code review.

With anglr, there is a better way:

import math
from anglr import Angle
heading = Angle(get_compass_value())
if heading.angle_between(target) <= math.pi / 4:
    print("Facing the target")
    print("Not facing the target")

Much better - this will now correctly take modular arithmetic into account when comparing angles.


Angle creation:

from math import pi
from anglr import Angle
print(Angle(87 * pi / 2))
print(Angle(pi / 2, "radians"))
print(Angle(Angle(pi / 2, "radians"))) # same as above
print(Angle(64.2, "degrees"))
print(Angle(384.9, "gradians"))
print(Angle(4.5, "hours"))
print(Angle(203.8, "arcminutes"))
print(Angle(42352.7, "arcseconds"))
print(Angle((56, 32), "vector")) # angle in standard position - counterclockwise from positive X-axis

Angle conversion:

from anglr import Angle
x = Angle(58.3)
print([x], str(x), x.radians, x.degrees, x.gradians, x.hours, x.arcminutes, x.arcseconds, x.vector, x.x, x.y)
x.radians = pi / 2
x.degrees = 64.2
x.gradians = 384.9
x.hours = 4.5
x.arcminutes = 203.8
x.arcseconds = 42352.7
x.vector = (56, 32)

Angle arithmetic:

from math import pi
from anglr import Angle
print(Angle(pi / 6) + Angle(2 * pi / 3))
print(x * 2 + Angle(3 * pi / 4) / 4 + 5 * Angle(pi / 3))
print(Angle(-4.3) <= Angle(pi / 4) > Angle(0.118) == Angle(0.118))
print(Angle(-870.3, "gradians").normalized())
print(Angle(-870.3, "gradians").normalized(0)) # same as above
print(Angle(-870.3, "gradians").normalized(0, 2 * pi)) # same as above
print(Angle(-870.3, "gradians").normalized(-pi, pi))
print(Angle(-870.3, "gradians").normalized(-pi, 0))
print(Angle(1, "degrees").angle_between_clockwise(Angle(0, "degrees")))
print(Angle(1, "degrees").angle_between(Angle(0, "degrees")))
print(Angle(0, "degrees").angle_within(Angle(-45, "degrees"), Angle(45, "degrees")))
print(Angle(-1, "degrees").angle_within(Angle(-1, "degrees"), Angle(1, "degrees"), strictly_within=True))
print(Angle(-1, "degrees").angle_to(Angle(180, "degrees")))
print(Angle(0, "degrees").angle_to(Angle(180, "degrees")))

To run all of the above as tests, simply run python3 in the project directory.


The easiest way to install this is using pip3 install anglr.

Otherwise, download the source distribution from PyPI, and extract the archive.

In the folder, run python3 install.


This library requires Python 3.2 or higher to run.


Uberi <> (Anthony Zhang)

Please report bugs and suggestions at the issue tracker!


Copyright 2014-2015 Anthony Zhang (Uberi).

The source code is available online at GitHub.

This program is made available under the 3-clause BSD license. See LICENSE.txt for more information.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for anglr, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size anglr-1.1.0-py3-none-any.whl (7.9 kB) File type Wheel Python version 3.4 Upload date Hashes View
Filename, size anglr-1.1.0.tar.gz (6.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page