Skip to main content

A Simple Package For Angle Calculation

Project description

PyAngle

A simple package for angle calculation

Use

install

pip install PyAngle

import

from PyAngle import *

class Angle

Designed especially for angle in the form of DMS(Degree, Minute and Second)

immutable object

default: public, non-static

import

from PyAngle.Angle import Angle

APIs

Creators

>>> a1 = Angle.from_dms(deg=30, min=20, sec=10)
>>> a2 = Angle.from_degrees(degrees=60)
>>> a3 = Angle.from_rad(rad=1.23)
>>> a4 = Angle.from_atan2(x=0.7, y=0.8)
>>> a5 = Angle(a4)
  • from_dms(deg, min=0, sec=0) -> Angle
  • from_degrees(degrees) -> Angle
  • from_rad(rad) -> Angle
  • from_atan2(x, y) -> Angle

Operators

>>> str(a1 + a2)
'90 20 10.00'
>>> str(a3 % a4)
'21 39 35.04'
>>> angle_list = [a1, a2, a3, a4]
>>> angle_list.sort(reverse=True)
>>> angle_list
[<PyAngle.Angle.Angle object at 0x0000020C195FD0F0>, <PyAngle.Angle.Angle object at 0x0000020C19521B38>, <PyAngle.Angle.Angle object at 0x0000020C195FD860>, <PyAngle.Angle.Angle object at 0x0000020C195D6EF0>]
>>> a3 > a4
True
  • __add__(self, other): "+"
  • __sub__(self, other): "-"
  • __mul__(self, n): "*"
  • __truediv__(self, n): "/"
  • __floordiv__(self, n): "//"
  • __mod__(self, other): "%"
  • __str__(self)
  • __cmp__(self, other)
  • __eq__(self, other): "=="
  • __ne__(self, other): "!="
  • __le__(self, other): "<="
  • __lt__(self, other): "<"
  • __ge__(self, other): ">="
  • __gt__(self, other): ">"
  • __hash__(self)

Calculators

>>> a2.sin()
0.8660254037844386
  • sin() -> float
  • cos() -> float
  • tan() -> float

Getters

>>> a4.get_deg()
48
>>> a4.get_sec()
50.66940344529314
  • get_deg() -> int
  • get_min() -> int
  • get_sec() -> float

Switchers

>>> [x.to_degrees() for x in angle_list]
[70.47380880109125, 60.0, 48.81407483429036, 30.336111111111112]
>>> a1.to_atan2(x=1)
(1, 0.5851986012863108)
>>> a3.to_fmt_str()
'70°28′25.71″'
  • to_degrees() -> float
  • to_rad() -> float
  • to_atan2(x=None, y=None) -> (float, float)
  • to_fmt_str(fmt="xxx°xxx′xxx″", decimal=2) -> str

Judges

>>> a3.is_acute_angle()
True
  • is_zero_angle() -> bool: 零角
  • is_acute_angle() -> bool: 锐角
  • is_right_angle() -> bool: 直角
  • is_obtuse_angle() -> bool: 钝角
  • is_straight_angle() -> bool: 平角
  • is_major_angle() -> bool: 优角
  • is_minor_angle() -> bool: 劣角
  • is_complementary_angle_with(other) -> bool: 余角
  • is_supplementary_angle_with(other) -> bool: 补角

module AngleListAPIs

import

from PyAngle.AngleListAPIs import *

APIs

>>> AngleListAPIs.from_angle_list_to_atan2_list(angle_list)
[(0.3342377271245026, 0.9424888019316975), (0.5000000000000001, 0.8660254037844386), (0.658504607868518, 0.7525766947068778), (0.8630773966838536, 0.5050716853412216)]
>>> AngleListAPIs.from_rad_list_to_angle_list([1.23, 1.0471975511965976, 0.8519663271732721, 0.5294650211397243])
[<PyAngle.Angle.Angle object at 0x0000028ED1910DD8>, <PyAngle.Angle.Angle object at 0x0000028ED1910E48>, <PyAngle.Angle.Angle object at 0x0000028ED1910EB8>, <PyAngle.Angle.Angle object at 0x0000028ED1910F28>]
  • from_atan2_list_to_angle_list(angles: [(float, float)]) -> ["Angle"]
  • from_degrees_list_to_angle_list(angles: [float]) -> ["Angle"]
  • from_rad_list_to_angle_list(angles: [float]) -> ["Angle"]
  • from_angle_list_to_atan2_list(angles: ["Angle"]) -> [(float, float)]
  • from_angle_list_to_degrees_list(angles: ["Angle"]) -> [float]
  • from_angle_list_to_rad_list(angles: ["Angle"]) -> [float]
# When needed to switch within atan2, degrees and rad, switch via angle list
>>> degrees_list = [1.2, 3.4, 5.6, 7.8, 9.0]
>>> atan2_list = AngleListAPIs.from_angle_list_to_atan2_list(AngleListAPIs.from_degrees_list_to_angle_list(degrees_list))
>>> atan2_list
[(0.9997806834748455, 0.020942419883356957), (0.9982398279237653, 0.05930637357596162), (0.9952273999818312, 0.09758289975914947), (0.9907478404714436, 0.13571557243430438), (0.9876883405951378, 0.15643446504023087)]
  • get_nearest_angle(angle: "Angle", angles: ["Angle"]) -> "Angle": 在angles中找到与angle最近的角
  • get_furthest_angle(angle: "Angle", angles: ["Angle"]) -> "Angle": 在angles中找到与angle最远的角
>>> nearest_angle = get_nearest_angle(angle, angles)

class UnlimitedAngle

degrees ranges [-∞, +∞] (without restrict)

import

from PyAngle.UnlimitedAngle import UnlimitedAngle
  • to_Angle(): switch UnlimitedAngle into Angle
>>> ua1 = UnlimitedAngle.from_degrees(degrees=1000)
>>> ua2 = UnlimitedAngle.from_degrees(degrees=-1000)
>>> ua3 = UnlimitedAngle(ua1)
>>> ua4 = UnlimitedAngle(Angle(UnlimitedAngle(ua2)))

Future Features

3.0

Draw Angle on Axis

  • plot(length, origin=(0, 0), base_angle=Angle.from_degrees(degrees=0), counter_clock_wise=True)

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

PyAngle-2.5.0.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file PyAngle-2.5.0.tar.gz.

File metadata

  • Download URL: PyAngle-2.5.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.8

File hashes

Hashes for PyAngle-2.5.0.tar.gz
Algorithm Hash digest
SHA256 d974549702e9177d8997fdd1b9413d1360e72a705405ec0b630d19d5003af78d
MD5 bf4fd843cb6883c1b62a65370838ed3a
BLAKE2b-256 785abf74607d1ede3defff34c55d21b4f13511d7efaa99f05d03907b6d9a95aa

See more details on using hashes here.

Supported by

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