Be the first to rate this file! 20 Downloads (last 30 days) File Size: 33.5 KB File ID: #37597

Efficient Vector Rotation Matrix Routine

by

 

23 Jul 2012 (Updated )

Efficient Method to Determine a Matrix Needed to Rotate One Vector to Another

| Watch this File

File Information
Description

Suppose you have a unit vector described by f = [ai bj ck] and you would like to rotate f such that its result is t = [di ej fk]. This routine will find R(f,t) such that R(f,t)*f’ = t’. Where R(f,t) is known as the 3 x 3 transformation matrix needed to rotate f into t.
This MATLAB routine was based on a published article titled “Efficiently Building a Matrix to Rotate One Vector to Another” written by Tomas Moller and John Hughes in 1999.

This method features no square roots or trigonometric function calls and is reported to be faster than any other vector rotation matrix method tested by Moller and Hughes. In fact, the Goldman method (fastest method tested) was 50% slower than this routine in conversion speed tests.

Working Example:

Unit Vector f:
>> f = rand(1,3);
>> f = f./norm(f);

Unit Vector t:
>> t = rand(1,3);
>> t = t./norm(t);

The transformation matrix R(f,t) is found:
>> R = vecRotMat(f,t);

Now, test that R*f’= t’
>> R*f’

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
23 Apr 2014 Darin Koblick

Alexander, you are correct. I went ahead and changed the vector angle check to be closer to 1 instead of 0.99. Also, I found that I needed to add the case where vectors where close to parallel (i.e. abs(c) > 1-1e-13) and two or more components had the same values. Thank you for pointing out the problem to me.

22 Apr 2014 Alexander

Thank you for submission. But if cosine of angle between vectors is >.99 (by module), calculation is incorrect.
A pair f=[1 0 0], t=[0.9904 0 -0.1380] can be used as an example.

10 Jan 2013 Jan Simon

There is some potential for accelerations:
1. Avoid calculatin ~idx 35 times, but use a temporary variable instead.
2. Matlab's CROSS and DOT implementations are very slow, so better calculate them inlined.

Updates
23 Apr 2014

Added robustness to parallel vector check. Added extra check to account for vectors that are parallel and have two or more identical values. Rotation error was found to be on the order of 1e-15.

Contact us