View Full Version : roll a sphere?

newmannium

03-04-2001, 09:28 AM

One more question:

If I want to roll a sphere on the x-z plane

by using translations and rotations.

How can I roll it from the point A(-4,1,4,1)

to the point B(3,1,-4,1) along with

a straight line, and make the rotation and

translation should match to produce the

effect of rolling the spere on the x-z plane?

Thanks a lot!

I'm not even going to try to figure out which plane is the x-z plane right now, but you should try figuring out which direction you want to roll it first (start by applying:

glRotated( 1.0, 1.0, 0.0, 0.0 )

each frame, if thats not right use:

glRotated( 1.0, 0.0, 1.0, 0.0 )

and if thats not right, use:

glRotated( 1.0, 0.0, 0.0, 1.0 )

You should be able to see which direction is the one you want.

Then start adding in your translation with glTranslate() until it looks right, translate it in the direction you want to go each frame by a little more than last frame (simple vector math).

You should be rolling your sphere around in no time.

Hello,

I'm taking a wild stab in the dark, here (well, any excuse to procrastinate, I feel <mutters about work he should be doing, but isn't doing right at the minute>=) but it SOUNDS like the original poster is trying to figure out what rotations/transformations s/he wants to get the ball to rotate along an arbitrary vector.

Righty. The things you need to know are:

1) the two end points of the trajectory,

2) some other point on the ground plane, and

3) the size of the sphere

from (1) you can compute how far you want the ball to roll, and along which vector. You also use the direction vector and (2) to figure out the plane its rolling on, and thus compute a vector along this plane that's orthogonal to the vector in (1). (3) will tell you how far the ball travels in one rotation (ie. the length of its circumfrence).

<thinks deep mathematical thoughts for a moment or two> If the ball is at angle *q* at time 0 at the start vertex, *a*, then for an arbitary point p along the vector from *ab*, then the ball would have rotated

|p-a|

------ * 2.0*pi radians about its axis since it started ... (1)

c

where |p-a| is the segment length from the start to the ball's position, and c is the circumfrence of the sphere. So, all you need to do is position the ball at p, and rotate it by eqn (1) about the vector found using the ground plane point and the vector (points 1 and 2 above)

nice, eh? I thought so. <basks in round of applause for several moments> thank you, thankyou.

er, you find p by interpolating along the line. easy to figure out. but not now; some sultry female just rang me up right now telling me that my order is ready, so i'm off! Mwhahahah.

cheers

John

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.