mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-15 15:20:37 -08:00
Added polar function
This commit is contained in:
parent
2850ac7266
commit
1f2db78c2c
3 changed files with 13 additions and 1 deletions
|
|
@ -126,4 +126,6 @@ __all__ = [
|
|||
"import_stl",
|
||||
"import_svg",
|
||||
"import_svg_as_buildline_code",
|
||||
# Other functions
|
||||
"polar",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue