Cutting and Splitting Polygons
In OpenGL, Quartz or Cocos2d is it possible to create a 2d polygon and then programatically intersect this shape with a line at any angle, creating 2 new shapes from the cut line?
For example: a 4 sided rectangle has line going through the shape at any angle from one side to another. This line is then used to split the polygon into 2 new shapes.
What kind of frameworks or technologies should I look into for doing things like this?
For example: a 4 sided rectangle has line going through the shape at any angle from one side to another. This line is then used to split the polygon into 2 new shapes.
What kind of frameworks or technologies should I look into for doing things like this?
If you are exclusively cutting convex polygons it's trivial to do. I have a snippet of code here that clips a polygon by a horizontal line, but it would be an easy modification to make it work with an arbitrary axis:
https://github.com/slembcke/Chipmunk-Phy...ancy.c#L58
For concave polygons it's little trickier as you can end up with more than 2 pieces, but the concept is basically the same.
https://github.com/slembcke/Chipmunk-Phy...ancy.c#L58
For concave polygons it's little trickier as you can end up with more than 2 pieces, but the concept is basically the same.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Thanks for the link. So I should use a framework like Cocos2d to draw the polygons and then use Chipmunk to do the physics side?
In my use case the polygons are 2d shapes in a 3d environment, will the new Cocos3d allow you to access Chipmunk's 2d physics engine?
In my use case the polygons are 2d shapes in a 3d environment, will the new Cocos3d allow you to access Chipmunk's 2d physics engine?
I wouldn't use Cocos2D unless you are drawing sprites, it's sort of a pain to do your own GL drawing in Cocos2D. I'd certainly recommend Chipmunk for physics of course.
(but there is also Box2D)
I can't speak for Cocos3D having never tried it. I can't imagine there would be anything preventing you from using the libraries together if you wanted to.
(but there is also Box2D)I can't speak for Cocos3D having never tried it. I can't imagine there would be anything preventing you from using the libraries together if you wanted to.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Combining then splitting angular and linear velocity | reubert | 4 | 4,126 |
Sep 5, 2006 12:47 AM Last Post: reubert |
|
| Collision Detection with concave-Polygons | mutle | 2 | 4,756 |
Jun 30, 2003 08:31 AM Last Post: codemattic |
|

