This commit is contained in:
Roger Maitland 2023-05-31 09:13:35 -04:00
commit bb4646fbbf
2 changed files with 34 additions and 1 deletions

View file

@ -630,6 +630,8 @@ class RadiusArc(BaseLineObject):
start_point (VectorLike): start
end_point (VectorLike): end
radius (float): radius
short_sagitta (bool): If True selects the short sagitta, else the
long sagitta crossing the center. Defaults to True.
mode (Mode, optional): combination mode. Defaults to Mode.ADD.
Raises:
@ -643,6 +645,7 @@ class RadiusArc(BaseLineObject):
start_point: VectorLike,
end_point: VectorLike,
radius: float,
short_sagitta: bool = True,
mode: Mode = Mode.ADD,
):
context: BuildLine = BuildLine._get_context(self)
@ -652,7 +655,10 @@ class RadiusArc(BaseLineObject):
# Calculate the sagitta from the radius
length = end.sub(start).length / 2.0
try:
sagitta = abs(radius) - sqrt(radius**2 - length**2)
if short_sagitta:
sagitta = abs(radius) - sqrt(radius**2 - length**2)
else:
sagitta = -abs(radius) - sqrt(radius**2 - length**2)
except ValueError as exception:
raise ValueError(
"Arc radius is not large enough to reach the end point."

View file

@ -166,6 +166,33 @@ class BuildLineTests(unittest.TestCase):
Spline((0, 0), (1, 1), (2, 0))
self.assertTupleAlmostEquals((test.edges()[0] @ 1).to_tuple(), (2, 0, 0), 5)
def test_radius_arc(self):
"""Test center arc as arc and circle"""
with BuildSketch() as s:
c = Circle(10)
e = c.edges()[0]
r = e.radius
p1, p2 = e @ 0.3, e @ 0.9
with BuildLine() as l:
arc1 = RadiusArc(p1, p2, r)
self.assertAlmostEqual(arc1.length, 2 * r * pi * 0.4, 6)
self.assertAlmostEqual(arc1.bounding_box().max.X, c.bounding_box().max.X)
arc2 = RadiusArc(p1, p2, r, short_sagitta=False)
self.assertAlmostEqual(arc2.length, 2 * r * pi * 0.6, 6)
self.assertAlmostEqual(arc2.bounding_box().min.X, c.bounding_box().min.X)
arc3 = RadiusArc(p1, p2, -r)
self.assertAlmostEqual(arc3.length, 2 * r * pi * 0.4, 6)
self.assertGreater(arc3.bounding_box().min.X, c.bounding_box().min.X)
self.assertLess(arc3.bounding_box().min.X, c.bounding_box().max.X)
arc4 = RadiusArc(p1, p2, -r, short_sagitta=False)
self.assertAlmostEqual(arc4.length, 2 * r * pi * 0.6, 6)
self.assertGreater(arc4.bounding_box().max.X, c.bounding_box().max.X)
def test_center_arc(self):
"""Test center arc as arc and circle"""
with BuildLine() as arc: