# Collision points.

Page 1 of 1

## 1 Replies - 784 Views - Last Post: 16 October 2013 - 09:45 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=331686&amp;s=25a8b01b75cdc046e9845684014dc294&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 novakasss

• D.I.C Regular

Reputation: 4
• Posts: 440
• Joined: 11-July 12

# Collision points.

Posted 16 October 2013 - 07:46 AM

I have read this article and I have one question. If I have oval shape, is there a better way to detect collision than using collsion points? Because oval shape can collide with all points that surrounds the actual shape. Or it would be OK to set only 8 points(up,down,left,right,left-up, left-down,right-up,right-down all 45 degrees)?

This post has been edited by novakasss: 16 October 2013 - 07:46 AM

Is This A Good Question/Topic? 0

## Replies To: Collision points.

### #2 BetaWar

• #include "soul.h"

Reputation: 1369
• Posts: 7,874
• Joined: 07-September 06

## Re: Collision points.

Posted 16 October 2013 - 09:45 AM

Well, and oval, as drawn on a computer, is really just a series of short lines with angles between each of them. That being said, and because ovals are convex shapes, you can take the center of mass (center of the shape) and keep that with the shape. Then you can check the bounding box for a collision with a point (basically draw a box around the oval and see if the point in question is inside that box or not; if not you aren't colliding with the object), and if you are colliding you run through all of the small lines (each vertex pair) and, using vector math and the cross product, you check to see if the center of mass and the point in question are on the same side of all of the lines. If they are then you have a collision. If any of the lines comes back false you don't have a collision.

Now, when working with sprites and pixel-art you can use points as they show for an oval, it just requires more points to get the curve approximately correct. As you can see in the article, they aren't going for pixel-perfect collisions, just close. It is also worth noting that they allow for concave and convex shapes to correctly approximate collisions through that method, whereas the above method only works for convex shapes.

Hopefully that makes some sense.
Was This Post Helpful? 2

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}