Added polar function

This commit is contained in:
Roger Maitland 2023-03-06 09:39:16 -05:00
parent 2850ac7266
commit 1f2db78c2c
3 changed files with 13 additions and 1 deletions

View file

@ -126,4 +126,6 @@ __all__ = [
"import_stl",
"import_svg",
"import_svg_as_buildline_code",
# Other functions
"polar",
]

View file

@ -43,7 +43,7 @@ import warnings
from abc import ABC, abstractmethod
from io import BytesIO
from itertools import combinations
from math import degrees, inf, pi, sqrt
from math import degrees, radians, inf, pi, sqrt, sin, cos
from typing import Any, Dict, Iterable, Iterator, Optional, Tuple, Type, TypeVar, Union
from typing import cast as tcast
from typing import overload
@ -6894,3 +6894,8 @@ def sort_wires_by_build_order(wire_list: list[Wire]) -> list[list[Wire]]:
)
return return_value
def polar(length: float, angle: float) -> tuple[float, float]:
"""Convert polar coordinates into cartesian coordinates"""
return (length * cos(radians(angle)), length * sin(radians(angle)))

View file

@ -988,6 +988,11 @@ class TestFunctions(unittest.TestCase):
self.assertAlmostEqual(wires[0].length, 4, 5)
self.assertAlmostEqual(wires[1].length, 6, 5)
def test_polar(self):
pnt = polar(1, 30)
self.assertAlmostEqual(pnt[0], math.sqrt(3) / 2, 5)
self.assertAlmostEqual(pnt[1], 0.5, 5)
class TestImportExport(unittest.TestCase):
def test_import_export(self):