85 lines
2.4 KiB
Python
85 lines
2.4 KiB
Python
from decimal import Decimal
|
|
import sympy as sp
|
|
import math
|
|
|
|
class Einheitenumrechnung:
|
|
"""Einheitenumrechnungen für Winkel- und Längeneinheiten.
|
|
|
|
Die Klasse stellt Methoden zur Verfügung für:
|
|
|
|
- Umrechnung von Millibogensekunden (mas) in Radiant,
|
|
- Umrechnung von Millimetern (mm) in Meter,
|
|
- Umrechnung von Gon und Milligon (mgon) in Radiant (Decimal-basiert).
|
|
"""
|
|
|
|
def mas_to_rad(mas: float) -> float:
|
|
"""Rechnet Millibogensekunden (mas) in Radiant um.
|
|
|
|
Es gilt: rad = mas * (pi / (180 * 3600 * 1000)).
|
|
|
|
:param mas: Winkel in Millibogensekunden (mas).
|
|
:type mas: float
|
|
:return: Winkel in Radiant.
|
|
:rtype: float
|
|
"""
|
|
umrechnungsfaktor = 1 / 1000 * 1 / 3600 * sp.pi / 180
|
|
grad = mas * umrechnungsfaktor
|
|
return grad
|
|
|
|
def mm_to_m(mm: float) -> float:
|
|
"""Rechnet Millimeter in Meter um.
|
|
|
|
Es gilt: m = mm / 1000.
|
|
|
|
:param mm: Länge in Millimeter.
|
|
:type mm: float
|
|
:return: Länge in Meter.
|
|
:rtype: float
|
|
"""
|
|
m = mm / 1000
|
|
return m
|
|
|
|
def gon_to_rad_Decimal(gon: float) -> Decimal:
|
|
"""Rechnet Gon in Radiant um (Decimal-basiert).
|
|
|
|
Es gilt: 400 gon = 2*pi und damit rad = (gon / 200) * pi.
|
|
|
|
:param gon: Winkel in Gon.
|
|
:type gon: float
|
|
:return: Winkel in Radiant als Decimal.
|
|
:rtype: Decimal
|
|
"""
|
|
gon = Decimal(gon)
|
|
pi = Decimal(str(math.pi))
|
|
rad = (gon / Decimal(200)) * pi
|
|
return rad
|
|
|
|
def mgon_to_rad_Decimal(gon: float) -> Decimal:
|
|
"""Rechnet Milligon (mgon) in Radiant um (Decimal-basiert).
|
|
|
|
Es gilt: 1 mgon = 0.001 gon und damit rad = (mgon / 200000) * pi.
|
|
|
|
:param gon: Winkel in Milligon (mgon).
|
|
:type gon: float
|
|
:return: Winkel in Radiant als Decimal.
|
|
:rtype: Decimal
|
|
"""
|
|
gon = Decimal(gon)
|
|
pi = Decimal(str(math.pi))
|
|
rad = (gon / Decimal(200000)) * pi
|
|
return rad
|
|
|
|
def rad_to_gon_Decimal(rad: float) -> Decimal:
|
|
"""Rechnet Radiant in Gon um (Decimal-basiert).
|
|
|
|
Es gilt: 400 gon = 2*pi und damit rad = (gon / 200) * pi.
|
|
|
|
:param rad: Winkel in Rad.
|
|
:type rad: float
|
|
:return: Winkel in Gon als Decimal.
|
|
:rtype: Decimal
|
|
"""
|
|
rad = Decimal(rad)
|
|
pi = Decimal(str(math.pi))
|
|
gon = (rad / pi) * Decimal(200)
|
|
return gon |