Rotation around a pivot

6 views
Skip to first unread message

Nick

unread,
Feb 13, 2011, 6:38:08 AM2/13/11
to Physics2D.Net
Morning everyone.

Firstly, hello I have just started using physics2d.net and so far I am
very impressed with it. It is much more "usable" than other engines I
have looked at from a developer point of view.

To my query,

is there any means for rotating bodies around a pivot in
physics2d.net? to give my question context I shall explain my
situation, currently I have a square made up of 4 rectangle shapes.
Within this square is a box, In my own implementation what I then did
was rotate the four walls and the box around a centre point. This
meant that a box sat on the floor would (before the physics took over)
be sat on a side wall, then the physics would kick in and it would
slide down to the ground.

To clarify potential confusions when an object is rotated around 90
degrees its top will now be its side however gravity etc will always
be downwards (i.e. y++, x nothing).

With luck my question is clear enough.

Thanks

Nick

Nick

unread,
Feb 13, 2011, 4:36:45 PM2/13/11
to Physics2D.Net
Here is a quick sketch based on a slight reworking of how I have
implemented this in the past.
When I get a chance ill attempt to put this into code and see how it
works as I am taking it there is no easy way from the silence :o)

http://i56.tinypic.com/2is8fw9.png

Nick

JonoPorter

unread,
Feb 14, 2011, 1:09:47 PM2/14/11
to Physics2D.Net
There are several Joints. Look at the Pivot Joint I believe its
called.

GusmanB

unread,
Feb 14, 2011, 5:14:27 PM2/14/11
to Physics2D.Net
Hi.

You can achieve this by using Sin and Cos functions, it's easy:

Lets supose you have your "anchor" point at (10, 10) and want to put
your object at a distance from the anchor of 5 units.

First rotate your object the amount you want (for all my explanation i
will work in radians), lets supose the object must be on the right of
the anchor initially, a PI / 2 rotation must be applied (90º), if it
must be on top of the anchor point it will be a rotation of 0rad (0º),
under it a rotation of PI (180º), etc...

Once the object is rotated, to calculate the position of the object
you must set it at (10, 10) + (Math.Sin(angle) * distance,
Math.Cos(angle) * distance), in our example it will be (10 +
(Math.Sin(Math.PI / 2d) * 5), 10 + (Math.Cos(Math.PI / 2) * 5)).

I'm doing this in my head, i don't remember if the objects rotation
must be inverted (multiply it by -1 and it's ok), try it by yourself.

Hope it helps.

Nick

unread,
Feb 16, 2011, 4:03:03 PM2/16/11
to Physics2D.Net
Thanks, I took a slightly different slant on it in the end for reasons
how how it will fit into the end result but here is a demo of it in
action.

Thanks all.

http://tinypic.com/r/yh5bq/7
Reply all
Reply to author
Forward
0 new messages