Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rotate a vector...

5 views
Skip to first unread message

Ben Horner

unread,
May 23, 2002, 9:54:14 AM5/23/02
to
How do you rotate a vector towards another vector through a certain
angle? I know how to find the angle between two vectors, but not how to
change a vector by an angle.
Say I have the vector <10, 10, 10> and I want to rotate it 10 degrees
towards vector <5, 7, 12>... How do you do that? I think you can
bisect the angle between them by averaging the components...
<7.5, 8.5, 11>, but how would I do the 10 degrees thing?
I'd really like a one shot solution, like a function of variables
rather than an algorithm, especially an iterative algorithm.
Any restrictions you'd like to impose are fine, like just unit
vectors, angles measured in radians...

To restate the problem:
given: v1 = <a, b, c> and
v2 = <d, e, f>
v1 not parallel to v2
angle r
How do you find v3 = <g, h, i> such that the angle between v1 and v3 is
r, and v1, v2, and v3 are coplanar?

There is at least one restriction I missed there, that v1 is rotated
"towards" v2 by the angle r to achieve v3. (if r was negative it would
be "away").

I would like to see an answer like g = f(a, d); h = f(b, e); i = f(c, f)
but anything would be helpful!
Thanks in advance!
-Ben

Peter Spellucci

unread,
May 23, 2002, 12:01:54 PM5/23/02
to

In article <MPG.1756b0682...@news.cis.dfn.de>,
Ben Horner <hor...@wernervas.com> writes:

snip


>To restate the problem:
>given: v1 = <a, b, c> and
> v2 = <d, e, f>
> v1 not parallel to v2
> angle r
>How do you find v3 = <g, h, i> such that the angle between v1 and v3 is
>r, and v1, v2, and v3 are coplanar?
>
>There is at least one restriction I missed there, that v1 is rotated
>"towards" v2 by the angle r to achieve v3. (if r was negative it would
>be "away").


what please is "towards" ? the problem can be reduced into a two dimensional
one (irrespective of the dimension of v_i) Now, usually towards means
in the mathematical positive sense, hence counterclockwise?
* *
* | *
* | *
* | *
* -------------------> VT1
* /
* \ /
_* /
/
/
VT2

>I would like to see an answer like g = f(a, d); h = f(b, e); i = f(c, f)
>but anything would be helpful!
>Thanks in advance!
>-Ben

now the reduction to this case:

you use two Householder reflectors to do this (and after rotation
in the x1-x2-plane transform back)
If
v1 = (a,b,c)' (I think of vectors always as columns)
then
h1= ( sign(a)*(|a|+sqrt(a^2+b^2+c^2)) , b , c )'
(here sign(0)=1)

and you set
vt1 = sign(a)*v1 -2* sign(a)*h1* (h1'*v1)/(h1'*h1)
vt2 = sign(a)*v2 -2*sign(a)*h1*(h1'*v2)/(h1'*h1) = ( g,h,i)' (say)
(the corresponding Householderreflector is
sign(a)*(Id - (2/(h1'*h1))*h1*h1' )
remark: h1'*h1 is a scalar, the sum of squares of the components of h1, but
h1*h1' is a 3 by 3 matrix.})

Now vt1 is a positive multiple of (1,0,0)' .
next you treat vt2 similar:

h2 = ( 0 , sign(h)*(|h|+sqrt(h^2+i^2)),i )'
vtt2=sign(h)*vt2 - sign(h)*2*((h2'*vt2)/(h2'*h2))*h2 ;
vtt1 =sign(h)*vt1
now vtt2 has a positive second component and a zero in component 3.
vtt1 is a positive multiple of (1,0,0)' if h>=0 and otherwise a negative
multiple.
(if vectors are longer, anything is done word for word the same way, the sqrt()
has as argument the sum of squares of the components 1..n resp 2..n and the
remaining components of the h_i are copies of the components of the vectors to be
treated. )
what you mean by "towards" is now determined by those signs.

now the rotation applies to components 1 and 2 only, multiplying them by
the matrix

[ cos(phi) , -sin(phi) ]
[ sin(phi) , cos(phi) ]
where 0<phi<2*pi is in radians
this is counterclockwise, if you need it clockwise, exchange the "-" before the
"sin" (i.e. transpose the matrix).
now the vector wanted is obtained by transforming it (vvt1-rotated) back
in reverse order
multiply by sign(h) to obtain some vector w,
then
w_back=sign(a)*w-sign(a)*2*(h1'*w)/(h1'*h1)
done (and hopefully correct)
peter


Lutz Tautenhahn

unread,
May 23, 2002, 12:42:06 PM5/23/02
to
> given: v1 = <a, b, c> and
> v2 = <d, e, f>
> v1 not parallel to v2
> angle r
> How do you find v3 = <g, h, i> such that the angle between v1 and v3 is
> r, and v1, v2, and v3 are coplanar?

Hello Ben,

v3 = v3|| + v3|_ (where v3|| is parallel to v1), so you get
v3 = cos(r) * v1 + sin(r) * (v1 x v2) x v1 / |v1 x v2|
(where x denotes the cross product of 2 vectors and |v| is the lenght of
a vector v). This can also be transformed into
v3 = cos(r) * v1 + sin(r) * ((v1 v1) v2 - (v1 v2) v1) / |v1 x v2|
(where (v1 v2) is the dot product of the 2 vectors).
For other vector rotating problems have a look at my webpage (in german) at
http://www.tu-chemnitz.de/~luta/drawlat/drawmath.html

Hope this helps,
Lutz Tautenhahn

0 new messages