Skip to main content

A class for representing and performing calculations with angles.

Project description

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. 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.

Project details


Download files

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

Source Distribution

angle-headings-1.1.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

angle_headings-1.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file angle-headings-1.1.1.tar.gz.

File metadata

  • Download URL: angle-headings-1.1.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for angle-headings-1.1.1.tar.gz
Algorithm Hash digest
SHA256 910c5bf714828fca1d9cadabe0a375ed76d2d312e5602bb1714adf71f81649d2
MD5 b95043e19d4de407a83403eff340f08f
BLAKE2b-256 46a809789280454876f9ac36b37657a7a7368cfce35fecbf6a4fa97b010890f5

See more details on using hashes here.

File details

Details for the file angle_headings-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: angle_headings-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for angle_headings-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a64ed636ff33f92846610c7d87a5059b50fbcf6b7c283437c4b89d7d73a6a87
MD5 aa2772d84382d5ab8e213f0621eee4a9
BLAKE2b-256 b632888a204c8b50c211073c5987f5c2b4d4491730613cba74910ca2358a5dba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page