wrong area computation
GoogleCodeExporter opened this issue · 3 comments
GoogleCodeExporter commented
What steps will reproduce the problem?
1. create a convex polygon shape with points turning around the origin
What is the expected output? What do you see instead?
positive area. The result is instead negative and so raises assert at line 115.
What version of the product are you using? On what operating system?
Please provide any additional information below.
The problem is in the formula
float32 D = b2Cross(e1, e2); // LINE 105
This product can be NEGATIVE if vector's directions are opposite (as in my
case, the first point in the third quadrant, the next is in the first one).
Next the code is the following:
float32 triangleArea = 0.5f * D; // LINE 107
area += fabs(triangleArea); // LINE 108
But it must be:
area += fabs(triangleArea); // LINE 108 i.e. you must keep the ABS area value.
Bye,
Roberto Sartori
roberto.sartori@gmail.com
www.rawfish.it
Original issue reported on code.google.com by roberto....@gmail.com
on 13 Sep 2012 at 2:48
GoogleCodeExporter commented
missing info: the source code I was referring is b2PolygonShape.cpp, the actual
code line is
area += triangleArea;
instead it must be
area += fabs(triangleArea);
Original comment by roberto....@gmail.com
on 13 Sep 2012 at 2:50
GoogleCodeExporter commented
But the vector directions being opposite is an unsupported case, and needs to
be detected. The polygon winding is expected to be counter-clockwise, which
gives a positive area. If the winding is clockwise the area will be negative,
and should be kept negative to hit the assert at the end of the function:
b2Assert(area > b2_epsilon);
Using fabs to force the area to be positive would skip this important assertion.
Original comment by iforc...@gmail.com
on 7 Mar 2013 at 3:46
GoogleCodeExporter commented
The code in the trunk already computes the convex hull and fixes the winding
order. So this issue no longer applies.
Original comment by erinca...@gmail.com
on 23 Oct 2013 at 6:53
- Changed state: Fixed