how to create a hollow circle and place bodies inside?

236 views
Skip to first unread message

sowenzhang

unread,
Aug 11, 2009, 5:25:36 PM8/11/09
to Physics2D.Net
Hi, all

I am trying to figure out how to create a hollow circle and place
other bodies inside it, so no "body" can excess this circle.

thanks a lot!

Bobby5808

unread,
Aug 15, 2009, 12:42:12 AM8/15/09
to Physics2D.Net
Hi sowenzhang

You can make a shape with a hole in it pretty easily, you just have to
define the shape vertexes yourself.

A circle with a hole in it is basically a "C" shape, with the 2 ends
of the "C" toucthing.

sowenzhang

unread,
Aug 15, 2009, 2:17:44 AM8/15/09
to Physics2D.Net
Hi, Bobby,
thanks for your response. I did try to draw circle and along the
circle edge, I create an array of vertex2D to create a Polygon, the
result is, this hollow circle is very thin, any body inside it can
easily pass through this boundary. So I created another smaller
circle, along the smaller circle edge, I get another array of
vertex2D; I combine two arrays together, hope to get a thicker hollow
circle. but the fact is, it's like a solid circle, when my program
starts, every body is supposed to inside the body is moved out to the
outside (their linearPosition is already different), and if I try to
drag body back in to the circle, I cannot pass through the edge. Could
you explain a little bit how exactly the vertex array works when
creating a polygon with it?

Bobby5808

unread,
Aug 16, 2009, 7:50:15 AM8/16/09
to Physics2D.Net
Heres a picture of how the vertexes should be arranged to make a hole.
To make it a closed circle, just make the ends right together. This is
just to show you how they should be arranged.

http://physics2ddotnet.googlegroups.com/web/circle_vertexes.JPG?gsc=QJbKEAsAAAC2YEPI0t59caxAxAmlSMOL
(the picture is also in the "files" section, if the link doesn't work)

A vertex array is basically the outline of the shape in anti-clockwise
order, and is always a closed shape. The vertex array of a square
would be the 4 corners.

Also, with physics engines you should never have shapes that are too
thin because of "tunneling", which happens when you have thin shapes
travelling too fast. Some engines can get around this (like BOX2D),
but its quite expensive calculating and can slow things down quite a
bit. So you should just make the circle thicker to avoid it.

Also, download Vertices.cs from the "files" section:

http://physics2ddotnet.googlegroups.com/web/Vertices+(2).cs?gda=grP9MkUAAAAMJfP-83FN243RrxxWSFQY3H6oysEoYKlvVseZEv_qvKFuRuhmtHBPbwfLnnTXgFjYW0ioaZv8t3hLHww7u3bTGu1iLHeqhw4ZZRj3RjJ_-A&gsc=yxomSAsAAADybm9VyO52alrX8EQp5QfP

Its a vertex helper class from the Farseer physics engine, which I
modified for Physics2D.NET. It has a function to cut a hole in a
shape, which might help you a bit.

To use it call: newvertexes = Vertices.CutHoleInShape
(bigcirclevertexes, smallcirclevertexes)
That will take bigcirclevertexes, and cut out a hole in it the shape
of smallcirclevertexes. You can use any sized shapes as either the
hole or the cutoutshape, just make sure that the cutout shape is
inside the main shape.

Cheers
Reply all
Reply to author
Forward
0 new messages