Skip to content

Commit bb95d56

Browse files
committed
Area is always positive, irrespective of vertex order
1 parent 5691222 commit bb95d56

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

spatialmath/geom2d.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,9 @@ def area(self):
300300
>>> p = Polygon2([[1, 3, 2], [2, 2, 4]])
301301
>>> p.area()
302302
303-
.. warning:: For a polygon with clockwise ordering of vertices the
304-
area will be negative.
305-
306303
:seealso: :meth:`moment`
307304
"""
308-
return self.moment(0, 0)
305+
return abs(self.moment(0, 0))
309306

310307
def centroid(self):
311308
"""
@@ -390,6 +387,8 @@ def moment(self, p, q):
390387
>>> p = Polygon2([[1, 3, 2], [2, 2, 4]])
391388
>>> p.moment(0, 0) # area
392389
>>> p.moment(3, 0)
390+
391+
Note is negative for clockwise perimeter.
393392
"""
394393

395394
def combin(n, r):
@@ -425,8 +424,6 @@ def prod(values):
425424
m += Al * s
426425

427426
return m / (p + q + 2)
428-
429-
430427
class Line2:
431428
"""
432429
Class to represent 2D lines

0 commit comments

Comments
 (0)