Jump to content
  • Advertisement
Sign in to follow this  
PhoenixGames

Changing the point of rotation with rodrigues' rotation formula

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I posted this a few months ago. I was trying to rotate a set of points around a sphere,

Based on the replies that I got, I made some progress, but I am still not quite there.

My current situation can be described best with the aid of THIS graphic (https://postimg.org/image/jkg1hs2fn/).

 

I tried to embed it, but wasn't able. 

 

Basically, the coloured polygons are a set of vertices that I am trying to move and rotate. 

In short, I would like to take the GREEN vertices (testgroup2) and rotate then so that they are in exactly the same position as the pink vertices (testgroup1).

I am working on a spherical terrain implementation, and all of these vertices are on the surface of the same sphere, so I should be able to rotate them around the origin of that sphere.

What I am trying to do is use Rodrigues rotation formula to handle the rotation.

This is the relevant section of code:

F32 x = renderlist[i].point.x;
F32 y = renderlist[i].point.y;
F32 z = renderlist[i].point.z;

Point3F v = Point3F(x, y, z); //get the point to be rotated

Point3F vec1 = v - Point3F(0, -10, 0); //get a vector from v to a new center point (0,-10,0)

v -= vec1; //subtract this vector from v

Point3F k = Point3F(1, 0, 0); //all rotation along x
F32 theta = -0.785398; //Rotation angle, 45 degrees

//Rodrigues' rotation formula:

Point3F vRot = v*mCos(theta) + mCross(k, v)*mSin(theta) + k*mDot(k, v)*(1 - mCos(theta)); //Rodrigues Formula, Important!
		
vRot += vec1; //add vec1 back to vRot


The above code produces the blue vertices in the image, or "testgroup4".

 

I am capable of performing the rotation, by any angle, however the issue is that the point of rotation for each of the testgroups is the "local" origin, ie, the center position of the purple vertices. Rotating around this origin gives me THIS result.

What I believe I need to do is to translate the nodes to the world space center of the planet, rotate them there, and then translate back. This is what I was trying to do in the above code, but it didn't seem to work.


I realise I am not explaining this very well, but can anyone offer any advice?

To summarise, I am trying to change the point around which rotation occurs when using Rodriques' rotation formula.

 

Share this post


Link to post
Share on other sites
Advertisement
Apply a translation first so the point (0,0,0) is the center of the sphere. Then rotate (with Rodrigues' formula or any other method). Then translate back.

That shouldn't be too hard to do. If you can't get it to work, try to post a detailed example of what happens to a single point.


  Point3F vec1 = v - Point3F(0, -10, 0); //get a vector from v to a new center point (0,-10,0)
  v -= vec1; //subtract this vector from v


That can't possibly be right. The second line is computing v -= v - Point3F(0, -10, 0). So after you do this, v = Point3D(0, 10, 0). Check with your debugger or with a print statement if that's the case.

EDIT: You probably just want to do this:

  Point3F center_of_rotation = Point3F(0, -10, 0);
  v -= center_of_rotation;
  // [rotation-around-the-origin code goes here]
  v += center_of_rotation
Edited by Álvaro

Share this post


Link to post
Share on other sites

Hello,

Thank you very much for your reply, your solution worked great!

I had gotten myself confused there I think, but I had been working on this problem for some time.

Is there some way for me to give you "reputation" or something for that solution?

Thanks again!

Share this post


Link to post
Share on other sites
You are welcome. You already upvoted me, which is the way to give me reputation. No further action required.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!