cpAreaForPoly() and cpPolyShape windings don't agree

Discuss any Chipmunk bugs here.

cpAreaForPoly() and cpPolyShape windings don't agree

Postby GrossSoftware » Fri Apr 01, 2011 11:45 am

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...

Posts: 1
Joined: Fri Apr 01, 2011 10:01 am

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

Postby slembcke » Fri Apr 01, 2011 12:03 pm

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! ->
User avatar
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests