Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2190.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mathematical approximations leading to potential issues - allowing rounding
4 changes: 3 additions & 1 deletion src/ansys/geometry/core/math/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def get_two_circle_intersections(
return None
else:
a = (r0**2 - r1**2 + d**2) / (2 * d)
h = np.sqrt(r0**2 - a**2)
# abs is used to ensure non-negative value - close to zero
# conditions might occur if circles are nearly tangent
h = np.sqrt(abs(r0**2 - a**2))
x2 = x0 + a * (x1 - x0) / d
y2 = y0 + a * (y1 - y0) / d

Expand Down
5 changes: 5 additions & 0 deletions src/ansys/geometry/core/sketch/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ def arc_from_start_end_and_radius(
-------
Sketch
Revised sketch state ready for further sketch actions.

Warnings
--------
This method may not produce the exact same radius, depending on the input parameters.
This is due to the mathematical approximations involved in the arc creation.
"""
arc = Arc.from_start_end_and_radius(
start,
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Angle, Distance
from ansys.geometry.core.modeler import Modeler
from ansys.geometry.core.sketch import Sketch
from ansys.geometry.core.sketch.arc import Arc
from ansys.geometry.core.tools import (
MeasurementTools,
PrepareTools,
Expand Down Expand Up @@ -371,3 +372,25 @@ def test_issue_2184_prevent_raw_instantiation_of_tools_and_commands():
GeometryRuntimeError, match="GeometryCommands should not be instantiated directly"
):
GeometryCommands(None)


def test_issue_2074_rounding_math_errors():
"""Test that rounding errors in math operations do not cause issues.

For more info see
https://github.com/ansys/pyansys-geometry/issues/2074
"""
sketch1 = Sketch()
width = 7
start = Point2D([width / 2, 0], UNITS.mm)
end = Point2D([-width / 2, 0], UNITS.mm)
radius = width / 2 * UNITS.mm
sketch1.arc_from_start_end_and_radius(start, end, radius)

arc: Arc = sketch1.edges[-1]

assert arc.center is not None
assert np.allclose(arc.center, Point2D([0, 0], UNITS.mm))
assert np.isclose(arc.radius.to_base_units().m, radius.to_base_units().m)
assert arc.start == start
assert arc.end == end