{"action":"created","issue":{"url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3558","labels_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3558/labels{/name}","comments_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3558/comments","events_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3558/events","html_url":"https://github.com/openframeworks/openFrameworks/issues/3558","id":54401545,"number":3558,"title":"ofPolyline getCentroid2D() can return NAN / infinity coordinates","user":{"login":"armadillu","id":167057,"avatar_url":"https://avatars.githubusercontent.com/u/167057?v=3","gravatar_id":"","url":"https://api.github.com/users/armadillu","html_url":"https://github.com/armadillu","followers_url":"https://api.github.com/users/armadillu/followers","following_url":"https://api.github.com/users/armadillu/following{/other_user}","gists_url":"https://api.github.com/users/armadillu/gists{/gist_id}","starred_url":"https://api.github.com/users/armadillu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/armadillu/subscriptions","organizations_url":"https://api.github.com/users/armadillu/orgs","repos_url":"https://api.github.com/users/armadillu/repos","events_url":"https://api.github.com/users/armadillu/events{/privacy}","received_events_url":"https://api.github.com/users/armadillu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-15T01:29:22Z","updated_at":"2015-01-15T19:45:38Z","closed_at":null,"body":"On perfectly decent ofPolylines (meaning with valid non-NAN points), you do get sometimes a centroid with x / y that's NAN. I suspect its related to the calculated area being zero. I can't fully test now, but I was getting NANs which where propagating to other parts of the code and ultimatelly leading to crashes while working with lots of user-generated ofPolylines.\r\n\r\nI switched to .getBoundingBox().getCenter() which was good enough for the project, and I got no more NAN's. "},"comment":{"url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/comments/70148713","html_url":"https://github.com/openframeworks/openFrameworks/issues/3558#issuecomment-70148713","issue_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3558","id":70148713,"user":{"login":"bilderbuchi","id":327442,"avatar_url":"https://avatars.githubusercontent.com/u/327442?v=3","gravatar_id":"","url":"https://api.github.com/users/bilderbuchi","html_url":"https://github.com/bilderbuchi","followers_url":"https://api.github.com/users/bilderbuchi/followers","following_url":"https://api.github.com/users/bilderbuchi/following{/other_user}","gists_url":"https://api.github.com/users/bilderbuchi/gists{/gist_id}","starred_url":"https://api.github.com/users/bilderbuchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bilderbuchi/subscriptions","organizations_url":"https://api.github.com/users/bilderbuchi/orgs","repos_url":"https://api.github.com/users/bilderbuchi/repos","events_url":"https://api.github.com/users/bilderbuchi/events{/privacy}","received_events_url":"https://api.github.com/users/bilderbuchi/received_events","type":"User","site_admin":false},"created_at":"2015-01-15T19:45:38Z","updated_at":"2015-01-15T19:45:38Z","body":"mathematically, it's pretty clearly defined:\r\n\r\n> In mathematics and physics, the centroid or geometric center of a two-dimensional region is the arithmetic mean (\"average\") position of all the points in the shape. \r\n\r\nHere, \"points\" are the infinite points (e.g. of mass) making up the shape, not the vertices of a polygon.\r\n\r\nHowever, there's a [formula](http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon) given for the centroid of a polygon, are we using that one? I haven't yet done the math manually to see if this holds up with degenerate points, but I'd assume so from a quick glance."}}