Detecting non-physics collision between png images

I have two separate algorithms that detect collisions between rectangles and circles. The images I’m using have a custom shape, thus collisions are being detected even though the images aren’t touching each other. Does anybody have an algorithm that detects collisions between objects with a custom shape? Or is there a way I can use physics without altering the objects position because I’m currently using transition.to for my animations.

Here is the algorithm I’m using for the collision detection
 

local function hasCollided( obj1, obj2 ) if ( obj1 == nil ) then --make sure the first object exists return false end if ( obj2 == nil ) then --make sure the other object exists return false end local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax return (left or right) and (up or down) end

That function only checks to see if two rectangles overlap.  There is an algorithm called Separating Axis Theorem (SAT) that will check to see if two arbitrary polygons are overlapping.  The polygons must be convex in shape and in the Lua implementation the vertices must be listed in a counter-clockwise order.

See this thread:  http://forums.coronalabs.com/topic/52986-best-way-to-hit-test-against-irregular-object/

The poster found a Lua implementation of SAT.  I looked over it, but I’ve not tried it.  You might find this helpful.

Rob

Thanks for the help Rob

That function only checks to see if two rectangles overlap.  There is an algorithm called Separating Axis Theorem (SAT) that will check to see if two arbitrary polygons are overlapping.  The polygons must be convex in shape and in the Lua implementation the vertices must be listed in a counter-clockwise order.

See this thread:  http://forums.coronalabs.com/topic/52986-best-way-to-hit-test-against-irregular-object/

The poster found a Lua implementation of SAT.  I looked over it, but I’ve not tried it.  You might find this helpful.

Rob

Thanks for the help Rob