angle and axis of rotation given initial and final positions

fabrival
Posts: 2
Joined: Fri Jul 23, 2010 1:16 pm

angle and axis of rotation given initial and final positions

Post by fabrival »

Hello, inside my application I need to detect collisions of a number of possible paths with terrain.
Every path is a collection of capsules and I know the position of every capsule in 3D space.
I need to use only the Bullet Collision Detection Library.
The btCapsuleShape represents a capsule around the Y axis. Now I need to place the associated Collision Objects in the right positions.
I suppose that, after some manipulation, the problem can be reduced to map one vector onto another in 3D space through a rotation around an axis.
In the examples that I've seen the axis is known and the final position is unknown. I need to do the inverse in the most efficient way because this operation will be performed for a great number of times.

What is the most efficient way of finding the angle and axis of rotation which map one vector onto another?

I've seen that a quaternion can be efficiently used to apply a rotation to a vector, but I haven't found examples for the inverse situation. Could anyone indicate such an example? Would it be as efficient as the direct approach?

Thanks in advance.

Fabrizio
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: angle and axis of rotation given initial and final posit

Post by Erwin Coumans »

What API are you using? The btCollisionWorld::convexSweepTest takes a start and end transform.

Given a start and end orientation you can compute the axis and angle between both using btTransformUtil::calculateDiffAxisAngleQuaternion. See src\LinearMath\btTransformUtil.h

Is that what you need?
Thanks,
Erwin
fabrival
Posts: 2
Joined: Fri Jul 23, 2010 1:16 pm

Re: angle and axis of rotation given initial and final posit

Post by fabrival »

Thanks for your answer, Erwin!

With it I have realized that I made a wrong assumption: dealing with static paths (no time involved) I started working with the basic collision shapes and btCollisionWorld::contactPairTest(). Any hit, no matter if the closest one or not, would have stopped the test and discarded the path.
Now I see that btCollisionWorld::convexSweepTest () and btTransformUtil can be successfully used also in my case.

Thanks

Fabrizio