# rotating on sphere

This topic is 4493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, i've been trying to get something apparently simple working for days without anything working (arrg my maths are terrible!) so i though i'd ask for some help ;) (i won't explain what i want to do actually, only a simple situation that works the same way) let's suppose i have a sphere, centered at (0,0,0), and i have two points, A and B, on the sphere (on its border), and i know their (X,Y,Z) coords. how can i build a rotation matrix that, applied to point A, will give point B? thanks!

##### Share on other sites
Im pretty sure you (if you know that matrix goes on the left of the vector), that you can write a matrix filled with all variables, abcdef..etc for every slot. Then do the multiplication of the vector with the matrix. You will have some equations with the same variables in them ;) solve for them individually.

##### Share on other sites
Quote:
 Original post by Mariannelet's suppose i have a sphere, centered at (0,0,0), and i have two points, A and B, on the sphere (on its border), and i know their (X,Y,Z) coords. how can i build a rotation matrix that, applied to point A, will give point B?
vector3 axis = cross(A, B);float length = axis.length();float angle = atan2(length, dot(A, B));axis /= length;matrix4x4 m;m.loadAngleAxis(angle, axis);
I left out the check for A and B being nearly parallel, as well as the code for loadAngleAxis(). If you need more details, let me know (and perhaps mention what your matrix conventions are, i.e. 1d or 2d indexing, row- or column-major, and row or column vectors).

##### Share on other sites
The best way to do this (I asked a VERY simular question not 4 days ago)
To get your maths up to speed... take your time, its hard... but you do need it, you need it a LOT more than some one just posting code for a matrix manipulation.

Then google for rotation matricies (there is one each for X, Y & Z)

That tutorial I liked to will show you how to do matrix based maths (and more), and the google with point you at the matrix you need for a rotation.

Building a method to loop through the matrix and do the maths when you know all that is a total cake walk.

I just rescently did this to make a camera orbit objects selected by the player, so i speak from very recent experiance... but do learn the maths! its intresting and it's information you can re-use... I would strongly recormend against just copy-pasting someone elses code into your project as you will learn nothing from it.

##### Share on other sites
Quote:
 Original post by JDUKyou need it a LOT more than some one just posting code for a matrix manipulation.
For what it's worth, my post was meant to be more of a push in the right direction (in pseudocode form) rather than a copy-and-paste solution. I would however recommend the method of determining the angle in my example over the acos() method mentioned in the tutorials you linked to.

##### Share on other sites
thanks for the pseudo code, and for the link to the tutorial... i'll try to get things working! (it's hard to get to get that kind of stuff to work when you're too young and have not been at school long enough to learn all the maths O_o)

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 9
• 20
• 12
• 13
• 14
• ### Forum Statistics

• Total Topics
632143
• Total Posts
3004419

×