Marianne 163 Report post Posted April 29, 2006 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! 0 Share this post Link to post Share on other sites
dpadam450 2357 Report post Posted April 29, 2006 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. 0 Share this post Link to post Share on other sites
jyk 2095 Report post Posted April 29, 2006 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). 0 Share this post Link to post Share on other sites
JDUK 100 Report post Posted April 29, 2006 The best way to do this (I asked a VERY simular question not 4 days ago)is read through thisTo 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. 0 Share this post Link to post Share on other sites
jyk 2095 Report post Posted April 29, 2006 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. 0 Share this post Link to post Share on other sites
Marianne 163 Report post Posted April 29, 2006 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) 0 Share this post Link to post Share on other sites