Skip to main content

Angle Headings

A lightweight Python class for representing and performing calculations with angles.

This is a small class meant to simplify common operations with angle measures. The convention used for the arithmetic and comparison operations is meant to capture the idea that we are primarily interested in the smallest angle between two measures, regardless of the numbers, themselves. In particular this includes the following conventions:

  • Angles that differ by an integer number of revolutions are considered equivalent.
  • Output angle values are limited in size to ±1/2 full revolution. For example, radian angle measures are restricted to the interval (-π,π], while degree angle measures are restricted to (-180,180].
  • Angle comparisons are based on the smallest angle between the two input angles, and on whether the first angle is closer to being clockwise or counterclockwise from the first. By convention we say that A > B if the smallest angle between A and B places A counterclockwise relative to B, and A < B if the smallest angle between A and B places A clockwise relative to B.

Radian, degree, and gradian measure (or any arbitrary subdivision of the circle) are all supported. Methods perform calculations and return results using the measure of their own angle object, converting other angles or floats when necessary.

Installation and Usage

This package can be downloaded from PyPI using the following console command:

$ pip install angle-headings

It can then be imported into a Python program as the angle_headings package.

Since this package defines only a single class, it is recommended to use

from angle_headings import Angle

to avoid the need for the angle_headings prefix.

The angle_headings.Angle Class

The following is a brief description of selected attributes, custom methods, and overloaded methods for the angle_headings.Angle class.

Attributes

  • measure (float) -- Current measure of the angle, always normalized to ±1/2 full revolutions.
  • mod (float) -- Measure of a complete revolution (e.g. 2π for radian measure, 360 for degree measure).
  • unit (str) -- Name of the unit of measure.

Methods

  • __init__([measure[, mod]]) -- angle_headings.Angle class constructor. Accepts the following keyword arguments:
    • measure (float) [0.0] -- Initial angle measure.
    • mod (int, float, or str) ["radians"] -- Specifies measure unit. A numerical argument is treated as the measure of a full revolution, while a string argument is taken as the name of a standard unit (radians, degrees, or gradians).
  • convert(mod) -- Returns the angle's measure converted to a different unit.
  • reldiff(other) -- Returns a relative difference between this and another angles' measures, normalized so that 0 represents equality and 1 represents diametrically opposed angles. This is meant to be used as an alternative to direct equality comparisons due to the float measures.

float-Valued Operators

  • abs(A) -- Returns the absolute value of an angle's measure.
  • int(A) -- Returns an angle's measure, cast as an integer.
  • float(A) -- Returns an angle's measure, cast as a float.
  • round(A) -- Returns an angle's measure, rounded to the nearest integer.

angle_headings.Angle-Valued Operators

Unary Operators

  • +A -- Returns an exact copy of the angle_headings.Angle object.
  • -A -- Returns a copy of the angle_headings.Angle object with its measure negated.

Overloaded Binary Operators

Each of the following operators accepts either another angle_headings.Angle object or a float as its second argument. If given another angle_headings.Angle, the second angle_headings.Angle is converted to the first angle_headings.Angle's unit before the operation is performed. If given a float, the number is used directly.

  • A + B -- Returns an angle_headings.Angle object with the sum of two angles' measures.
  • A - B -- Returns an angle_headings.Angle object with the difference between two angles' measures.

Scalar Operators

  • A * b -- Returns an angle_headings.Angle object with its measure multiplied by a scalar.
  • A / b -- Returns an angle_headings.Angle object with its measure divided by a scalar.
  • A // b -- Returns an angle_headings.Angle object with its measure floor divided by a scalar.
  • A ** b -- Returns an angle_headings.Angle object with its measure raised to a scalar power.

Overloaded Boolean Operators

Each of the following operators accepts either another angle_headings.Angle object or a float as its second argument. If given another angle_headings.Angle, the second angle_headings.Angle is converted to the first angle_headings.Angle's unit before the operation is performed. If given a float, the number is used directly.

Equality Comparisons

Due to the fact that each angle's measure is stored as a float, it is not recommended to directly test measure equality, and to instead make use of the Angle.reldiff() method.

  • A == B -- Tests for equality of two measures (after unit conversion and normalization).
  • A != B -- Tests for inequality of two measures.

Order Comparisons

The following comparisons are based on the smallest angle between two given measures.

  • A > B -- Returns True if and only if the smallest angle between A and B places A counterclockwise relative to B.
  • A >= B -- Returns True if and only if A > B or A == B.
  • A < B -- Returns True if and only if the smallest angle between A and B places A clockwise relative to B.
  • A <= B -- Returns True if and only if A < B or A == B.

Metadata

Release files for angle-headings 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for angle-headings 1.1.1
File Size Uploaded
angle-headings-1.1.1.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for angle-headings 1.1.1
File Interpreter ABI Platform
angle_headings-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / angle-headings-1.1.1.tar.gz

Download URL angle-headings-1.1.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
910c5bf714828fca1d9cadabe0a375ed76d2d312e5602bb1714adf71f81649d2
BLAKE2b-256 checksum
How to use checksums
46a809789280454876f9ac36b37657a7a7368cfce35fecbf6a4fa97b010890f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release files / angle_headings-1.1.1-py3-none-any.whl

Download URL angle_headings-1.1.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a64ed636ff33f92846610c7d87a5059b50fbcf6b7c283437c4b89d7d73a6a87
BLAKE2b-256 checksum
How to use checksums
b632888a204c8b50c211073c5987f5c2b4d4491730613cba74910ca2358a5dba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page