Skip to content
Open
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
3 changes: 3 additions & 0 deletions Mapping/circle_fitting/circle_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def circle_fitting(x, y):
- The fitting error as a deviation metric (float).
"""

if len(x) != len(y):
raise ValueError("x and y must contain the same number of points")

sumx = sum(x)
sumy = sum(y)
sumx2 = sum([ix ** 2 for ix in x])
Expand Down
3 changes: 3 additions & 0 deletions docs/modules/3_mapping/circle_fitting/circle_fitting_main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Object shape recognition using circle fitting

This is an object shape recognition using circle fitting.

Each range observation supplies a pair of coordinates. The two input lists
must have equal lengths so each point contributes once to the fit.

.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/circle_fitting/animation.gif

The blue circle is the true object shape.
Expand Down
8 changes: 8 additions & 0 deletions tests/test_circle_fitting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import conftest
from Mapping.circle_fitting import circle_fitting as m

Expand All @@ -7,5 +8,12 @@ def test_1():
m.main()


@pytest.mark.parametrize("x, y", [([0, 2, 0, 1], [0, 0, 2]),
([0, 0, 2], [0, 2, 0, 1])])
def test_requires_paired_coordinates(x, y):
with pytest.raises(ValueError, match="same number"):
m.circle_fitting(x, y)


if __name__ == '__main__':
conftest.run_this_test(__file__)