-
Notifications
You must be signed in to change notification settings - Fork 839
Description
When using the Polygon::offsetInward
function I get an unexpected result for the following input:
Polygon polygon(
{Position(0.0, 0.0),
Position(1.0, 1.0),
Position(2.0, 1.0),
Position(3.0, 0.0),
Position(3.0, 1.0),
Position(3.0, 2.0),
Position(2.0, 3.0),
Position(1.0, 3.0),
Position(0.0, 2.0),
Position(0.0, 1.0)});
polygon.offsetInward(0.1);
The problem here is two-fold, the function does not seem to work well :
- for non-convex polygons (see sequence of points: 0, 1, 2, 3 in picture below),
- with points in the polygon that are positioned exactly (on a straight line) between their neighbors (see points 4 & 9, in picture below).
I have noticed the statement on non-convex polygons here, but that same statement is in a TODO
, so this might be the moment to address convex
part of the TODO
... :-)
A picture of the result is below (red dashed line is output of the offsetInward
function):
A small analysis (in Matlab which for me is a tool I'm most familiar with) shows some intermediate steps in the process:
Here, the purple and green vectors at each point, are oriented towards their respective previous and next neighbor. Theses correspond with the v1 (purple) and the v2 (green) vectors of the function.
The black vectors is the summation of the green and purple vectors and is the direction over which the offset is applied.
Especially for the case of the 2nd problem I mention (points 4 & 9) it is obvious: the summation of these (v1+v2) equals zero, and therefore any offset value will be placed exactly on the point itself.