# Cutting a body in box2d

After cocos2d, I'm looking at box2d... And I have some questions:

I was wondering how to cut a body into pieces.

1. How do I determine the intersection point of the body with the cut line?

2. Create a new body in some "update_body_method"?

On the second question I have answer, for example between two points create vector from first point to second point.

There is an implementation of this in the C# library Velcro Physics (formerly Farseer Physics), which is based on Box2D: CuttingTools.cs

/src/VelcroPhysics/Tools/Cutting/Simple/CuttingTools.cs

// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
public static void Cut(World world, Vector2 start, Vector2 end, float thickness)

// Split a fixture into 2 vertice collections using the given entry and exit-point.
public static void SplitShape(Fixture fixture, Vector2 entryPoint, Vector2 exitPoint, float splitSize, out Vertices first, out Vertices second)

• For simple example I create one body and vector, vector construct on two points. Collision between vector and body works fine, but I still did not think how to get the intersection point of the vector and the body??? UPD: I have one idea, but... Jul 26 '11 at 13:04
• I believe you can use this method to get the intersection points : b2Shape.RayCast(...) code.google.com/p/box2d/source/browse/trunk/Box2D/Box2D/…
– Den
Jul 26 '11 at 14:04
• I found this method in documentation. Jul 26 '11 at 14:32
• From documentation:**You can cast a ray at a shape to get the point of first intersection and normal vector** It is only one point, but I need two points. May I use in this case Contact Manifolds??? Jul 27 '11 at 8:48
• In Farseer they cast a reverse ray to get the exit point. You can try reversing b2RayCastInput points to cast reversed ray to get exit point.
– Den
Jul 27 '11 at 9:02