Line Segments + Rotating a Circle at Constant Speed

Official forum for the Chipmunk2D Physics Library.
zacaj
Posts: 11
Joined: Sat Apr 11, 2009 3:55 pm
Contact:

Line Segments + Rotating a Circle at Constant Speed

Post by zacaj »

Ive got a few(hopefully simple questions).
1. How do I find the moment of inertia of a line segment?
2. Why dont line segments collide with each other?
3. How would I get a circle to roll at a constant speed(No accelleration)?

also:
with cpSpaceResizeActiveHash and cpSpaceResizeStaticHash
according to the moon demo, the first argument should be the average size of your objects, is this diameter, or radius? According to the moon demo, the second number is related to the number of objects you are putting, is this max or average number. In the docs, it says this should be around 10x the size, which isnt related to the number at all, so which one is right?

Thanks
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by maximile »

1. I'd be interested to know this too.
2. It's a legacy from when Chipmunk didn't support line segments with thickness. I usually just add two circles and a rectangle to simulate it (and approximate the moment of inertia using a poly shape).
3. It will roll at a constant speed along a flat surface. Down a hill, you could just set the velocity every frame.
also: Diameter. According to the docs, the second argument should be about 10x the *number* of objects, not the size.
zacaj
Posts: 11
Joined: Sat Apr 11, 2009 3:55 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by zacaj »

3. How would you get it to roll? I tried setting the torque, but then it accelerated..
Android_X
Posts: 18
Joined: Wed Oct 31, 2007 7:55 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by Android_X »

3. If you want it to rotate at a constant speed you could try: setting the angular velocity directly (body->w) and set the inertia to INFINITY so that collisions don't effect the rotation, eg cpBodySetMoment(body, INFINITY);
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by slembcke »

Undocumented, but exists in the trunk code. Copy paste away into your own project to use with 4.1.x

Code: Select all

cpFloat
cpMomentForSegment(cpFloat m, cpVect a, cpVect b)
{
        cpFloat length = cpvlength(cpvsub(b, a));
        cpVect offset = cpvmult(cpvadd(a, b), 1.0f/2.0f);
        
        return m*length*length/12.0f + m*cpvdot(offset, offset);
}
To get your constant rolling effect I'd go with what Android_X said. The infinite moment of inertia makes whatever angular velocity you set permanent. Because it's a circle, you don't have to worry about the infinite amount of torque it could produce because the only way the torque can escape is through friction.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
zacaj
Posts: 11
Joined: Sat Apr 11, 2009 3:55 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by zacaj »

The rolling works great, thanks. But the line segment acts really wierd...
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by slembcke »

Are you trying the same rolling behavior with a line segment? That might not work so well. It effectively has an infinite amount of torque driving it which might make it look stiff and unrealistic. It could also cause problems if something gets in the way of its turning as it would apply a nearly infinite amount of torque to push it out of the way.

It works well with circles because they only transfer that torque out by friction. The friction force is limited to the force pushing the two surfaces together multiplied by the frictional coefficient of the two surfaces so it can't be infinite.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
zacaj
Posts: 11
Joined: Sat Apr 11, 2009 3:55 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by zacaj »

No, the line segments just a regular body, falling under gravity
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by slembcke »

There is no collision detection function for checking line segments against other line segments if that is what you are asking.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
zacaj
Posts: 11
Joined: Sat Apr 11, 2009 3:55 pm
Contact:

Re: Line Segments + Rotating a Circle at Constant Speed

Post by zacaj »

No, its falling on a box
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 17 guests