I'm guessing you want the green line to be at 45 degrees?
First question is, how much do I rotate the vectors.
They both have to rotate an equal amount, I'm guessing.
For that, we first need to know then angle between the vectors. I'll call the vectors f and r (f = f - c, r = r - c).
The angle between the vectors is basically calculated using:
dot(f,r)=fx*rx+fy*ry+fz*rz = ||f||*||r||*Cos(angle)
So Angle = Acos(dot(f,r) /
|f||*||r||))
If the angle is 90, then we're good. If the angle is for example 30, then we need to rotate the vectors over an angle of 30 degrees.
So the amount we need to rotate is (we'll call it a):
a = 45 - 0.50*Angle
Now we need a rotation axis. For that we use the cross product. We'll call de rotation axis vector q.
q = f x r
q = q / ||q|| (to normalize our axis)
Btw, in case you don't know:
q = f x r :
q.x = f.y*r.z - f.z*r.y
q.y = f.z*r.x - f.x*r.z
q.z = f.x*r.y - f.y*r.x
This does give a problem if f and r are in the same direction, because then f x r = 0. You'll have to find a way to work around it.
So now we have a rotation axis, and the angle we need to rotate. Now how do we rotate?
For that we need to use a matrix to rotate around an arbitrary axis. We'll want to rotate one vector with the angle a and the other with the angle -a. I don't know which should be rotated with a and which with -a, but I suppose you can test it.
Now to rotate a vector around this arbitrary axis with angle a, we create the following matrix A, with:
A=[[A11 A12 A13]
[A21 A22 A23]
[A31 A32 A33]]
There might be some typing errors here
, but you can find this matrix on many sites (type in google: arbitrary axis rotation matrix)
A11 = q.x^2 + (q.y^2 + q.z^2)*Cos(a)
A12 = q.x*q.y*(1-Cos(a)) - q.z*Sin(a)
A13 = q.x*q.z*(1-Cos(a)) + q.y*Sin(a)
A21 = q.x*q.y*(1-Cos(a)) + q.z*Sin(a)
A22 = q.y^2 + (q.x^2 + q.z^2)*Cos(a)
A23 = q.y*q.z*(1-Cos(a)) - q.x*Sin(a)
A31 = q.x*q.z*(1-Cos(a)) - q.y*Sin(a)
A32 = q.y*q.z*(1-Cos(a)) + q.x*Sin(a)
A33 = q.z^2 + (q.x^2 + q.y^2)*Cos(a)
Now let's assume that we have to rotate f with angle a.
We do that by calculating:
f' = Af
Incase you don't know how it works:
f'.x = A11 * f.x + A12 * f.y + A13 * f.z
f'.y = A21 * f.x + A22 * f.y + A23 * f.z
f'.z = A31 * f.x + A32 * f.y + A33 * f.z
You do the same with r, but then you use a matrix built with the angle -a.
Of course after that, when you have calculate f' and r' you should add the vector c again to get the positions you want.
There might be a way easier way than this, but this what I though of first.
Kevil