I am trying to rotate a point say (20,6,30) around a point (10,6,10) at a radius of 2 and i have failed so far trying to do it. I know that to rotate a point around origin you just multiply rotation matrix with world matrix and to rotate a point around itself is translating the point to origin ,then rotating and translatingback, but not sure how to approach this problem.
How to rotate an object around a fixed point at a particular radius?
You can move your objects center of rotation by first translating before rotating.
So if you want to rotate about point p.
1. Translate your object to p
2. Do your rotation
3. Translate your object somewhere else
Good luck!
I am trying to rotate a point say (20,6,30) around a point (10,6,10) at a radius of 2
The above requirement can be fulfilled if the axis of rotation passes through (10,6,10) and passes through a point that is 2 length units away from (20,6,30).
Think of the rotational axis as a ray emanating at the center of rotation r0 (here (10,6,10)) along a direction d:
r( t ) := r0 + t * d
The second point is at a distance t1 on this ray. The difference vector v from here to the point of interest p (here (20,6,30)) is:
p - r( t1 ) =: v
It is constrained because it is perpendicular to d
v x d == 0
and its length should be 2
|| v || == 2
Try to solve this, but you'll see that there is an infinite amount of solutions to this. Think of a circle with radius 2 around p, and the 2nd point r( t1 ) on the ray may be any point of this circle. Whatever point you choose will have an influence on how the rotation looks like. EDIT: Ups, the figure isn't necessarily a circle, sorry. But it still may help as a gedanken experiment if thinking of a circle.
to rotate a point around itself is translating the point to origin ,then rotating and translatingback,
You almost have it. Instead of translating the point you want to rotate to the origin, translate the point you want to rotate around. (In fact this is exactly what is done in the algorithm you describe, but in that case the two points are identical.) So, given pointToRotate and rotateAround:
translation = (origin - rotateAround)
translation.applyTo(pointToRotate)
pointToRotate.rotate(angle)
translation *= -1
translation.applyTo(pointToRotate)
You can see that if pointToRotate and rotateAround are identical, this is precisely what you describe in your post.
I did a tutorial about this exact subject in my math series. Rotating one object around another.
@ DishSoap
Translate your object somewhere else
How would you calculate the position to be translated to as the position would be changed all the time due to rotation.
@ KingofMen
translation = (origin - rotateAround)
translation.applyTo(pointToRotate)
pointToRotate.rotate(angle)
translation *= -1
translation.applyTo(pointToRotate)
This would result in rotating around a fixed point but i want to change the radius of rotation, in this case the radius would be distance from a given point to the point with respect to which the object is rotating.
Thanks all for the replies , I'l post an answer once i find and test its working.