Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Averaging two rotations

Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
03-20-2009 05:41
Here's another rotation question. Say I have two rotations and I want a rotation that is somewhere in-between the two of them, how would I go about this?

For example, I have one rotation pointing 45º to the right, and one pointing 45º to the left, I want to calculate a rotation that is a weighted value composing 60% of the first rotation, and 40% of the second, the result of this should be a rotation pointing 9º to the right.

Is there an easy way to do this? I could probably come up with a messy way to do it by converting both rotations to Euler vectors, but it would likely be imperfect. Can this even be done using only the rotations?
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
03-20-2009 06:15
I'm hoping someone has a brilliant solution to this as I have been working on something very similar. As I follow along a defined path, when I change directions, I want to place a prim at that spot and rotate it to split the angle of the change of direction.

I have been working with llAtan2 to try to accomplish it. I have gotten close, but haven't quite gotten it right.

I can post some sample code later tonight if no one else comes up with an answer before then.
_____________________
Visit ChereeMotion - Life's Best Pinup Poses
http://slurl.com/secondlife/Wild%20Rice/38/230/51
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
03-20-2009 06:22
I would convert the two rotations to vectors in space, take the mean and convert back to a rotation.
Something like this:

rotation Ra =...;
Rotation Rb =...;
vector Va = llRot2Axis(Ra);
vector Vb = llRot2Axis(Rb);
vector Vm = 0.5*(Va+Vb);
rotation Rm = llAxes2Rot( < Vm.x, 0.0, 0.0 >, < 0.0, Vm.y, 0.0 >, < 0.0, 0.0, Vm.z >;);

Happy rotating:)
It does not look as if 'llRot2Axis' and 'llAxes2Rot' do what I want them to do. The concept has to be fiddled with:)
_____________________
From Studio Dora
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-20-2009 09:44
/54/3b/50692/1.html
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
03-20-2009 11:04
From: Hewee Zetkin


My eyes glazed over while reading that. But I now have bettter ways of doing it than what I was trying.

I will rework my code tonight. I hope the OP is getting help too.

Thanks Hewee and Dora (and Haravikk for asking this)
_____________________
Visit ChereeMotion - Life's Best Pinup Poses
http://slurl.com/secondlife/Wild%20Rice/38/230/51
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
03-20-2009 11:59
That thread has a very concise function that seems like it would do what I need, I've yet to try it but I'll cross-post Strife Onizuka's modified version:

CODE
rotation slerp( rotation a, rotation b, float t ) {
return llAxisAngle2Rot( llRot2Axis(b /= a), t * llRot2Angle(b)) * a;
}//Written collectively, Taken from http://forums.secondlife.com/showthread.php?p=536622


Thanks for the help!
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)