Examples » AngleValue

This class protects from sudden loss of 2π/180 factor

from pyxmolpp2 import Degrees, Radians
import numpy as np

To avoid accidental errors use of AngleValue is enforced by API.

AngleValue can be constructed via Degrees() or Radians():

a = Degrees(45)
b = Radians(np.pi)

It can be casted back to float as degrees or radians:

print(a.degrees, b.radians)
print(b.degrees, b.radians)
45.0 3.141592653589793
180.0 3.141592653589793

All basic arithmetic operations are supported:

print((a * 2 + b / 3).degrees)
149.99999999999997

AngleValue also has cos(), sin(), tan(), abs() methods for convenience:

print(a.cos(), a.sin(), a.tan(), a.abs().degrees)
0.7071067811865476 0.7071067811865475 0.9999999999999999 45.0

Sometimes we don't need extra periodic cycles and want our angle in [-\pi .. \pi) range. to_standard_range() functions would help you.

print("380 to [-180..180) range:",
      Degrees(380).to_standard_range().degrees)
380 to [-180..180) range: 20.00000000000003