Skip to content

Commit

Permalink
add function bulge_from_arc_angle() #758
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Oct 26, 2022
1 parent 3ebd949 commit 73b97da
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/source/math/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Bulge Related Functions
bulge_radius
bulge_to_arc
bulge_from_radius_and_chord
bulge_from_arc_angle

.. seealso::

Expand All @@ -91,6 +92,8 @@ Bulge Related Functions

.. autofunction:: bulge_from_radius_and_chord

.. autofunction:: bulge_from_arc_angle

2D Graphic Functions
====================

Expand Down
12 changes: 12 additions & 0 deletions src/ezdxf/math/bulge.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bulge_radius",
"arc_to_bulge",
"bulge_from_radius_and_chord",
"bulge_from_arc_angle",
]


Expand Down Expand Up @@ -171,3 +172,14 @@ def bulge_from_radius_and_chord(radius: float, chord: float) -> float:
return x / (1.0 + math.sqrt(1.0 - x * x))
except ValueError: # domain error
return 0.0


def bulge_from_arc_angle(angle: float) -> float:
"""Returns the bulge value for the given arc angle.
Args:
angle: arc angle in radians
"""
# https://github.com/mozman/ezdxf/discussions/758
return math.tan(angle/4.0)
14 changes: 14 additions & 0 deletions tests/test_06_math/test_601_bulge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2018 Manfred Moitzi
# License: MIT License
import pytest
import math
from ezdxf.math import (
bulge_radius,
Expand All @@ -8,6 +9,7 @@
bulge_3_points,
bulge_to_arc,
bulge_from_radius_and_chord,
bulge_from_arc_angle,
)


Expand Down Expand Up @@ -60,3 +62,15 @@ def test_radius_of_zero(self):
def test_too_small_radius_for_chord(self):
assert bulge_from_radius_and_chord(1, 10) == 0.0


@pytest.mark.parametrize("angle,bulge", [
(180, 1.0),
(-180, -1.0),
(106.26020471, 0.5),
(-106.26020471, -0.5),
(56.14497387, 0.25),
(-56.14497387, -0.25),
])
def test_bulge_from_arc_angle(angle, bulge):
assert math.isclose(bulge_from_arc_angle(math.radians(angle)), bulge)

0 comments on commit 73b97da

Please sign in to comment.