Page 1 of 1

cpAreaForPoly() and cpPolyShape windings don't agree

Posted: Fri Apr 01, 2011 11:45 am
by GrossSoftware
I ran into this problem recently and thought I'd mention it here. According to the documentation, the vertex winding for a cpPolyShape should be clockwise. However, calculating the area for the same set of vertices using cpAreaForPoly() returns a negative number. You'd think if the vertices were listed in the correct order, the calculated area would be positive.

As a side question, why is the winding CW? Most other physics/collision engines are CCW since the cross-product of adjacent vertex vectors is non-negative. Just wondering...

Jeff

Re: cpAreaForPoly() and cpPolyShape windings don't agree

Posted: Fri Apr 01, 2011 12:03 pm
by slembcke
Why yes, yes it is. :oops: I've actually only used it once and was squaring the result... Whoops.

The winding is clockwise because that's how I implemented it like 5 years ago. (It hasn't changed much in that time either) I've actually thought about changing it, but that would be a huge pain to users. All of the collision detection code was built from the ground up by me, and I didn't really have any previous experience when I started it.