Solved

Rotate vector using angular velocity to match another.

Posted on 2011-03-12
11
614 Views
Last Modified: 2012-05-11
I have a unit vector which I want to be able calculate the angular velocity it would need to rotate it so that it eventually faces the same direction as another unit vector.
0
Comment
Question by:codevomit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +1
11 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35117396
What info do you have? You just need to calculate the angle between them (using arccos(v1.x*v2.x+v1.y*v2.y)) and some intuition.
0
 
LVL 84

Expert Comment

by:ozo
ID: 35117752
wouldn't any angular velocity work, if you allow it to rotate for a sufficient amount of time?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35119094
For the game, given the time from start to finish, won't you want to accelerate and decelerate smootly for realism? In between the accelerations, you could rotate at constant velocity.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:codevomit
ID: 35161040
@ozo and @TommySzalapski, that would work for 2D but not for 3D, I assumed that 3D would be implied when asking this question. My bad for not stating that.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 35161075
In 3D, any angular velocity vector perpendicular to the plane of the unit vectors should work.
0
 
LVL 1

Author Comment

by:codevomit
ID: 35161123
That sounds more like it, I'll try that out tomorrow and get back to you.
0
 
LVL 1

Author Comment

by:codevomit
ID: 35168831
To get the angular velocity along a plane, I was thinking of using a cross product of the two vectors in a quaternion and rotating a vector (1,1,1) with it to give me angular movement in the appropriate direction, would that work?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35172491
I'm not sure what you mean by rotating "with it", but the cross product is a good tool. The vector that you get as a result of the cross product will be orthogonal (perpendicular) to both, so you want to use the cross product vector as the axis of rotation.
0
 
LVL 1

Author Comment

by:codevomit
ID: 35197156
"With it" means rotating a vector using a quaternion, pretty much what you and ozo have described. Anyway I've knocked something together in Unity that should do it, it doesn't work but I think I may of spotted my error, with assigning bot vect1 and vect2 as (1,1,1).

var rb : Transform;

function Update () {
       var vect1 : Vector3 =  Vector3.one;
       var vect2 : Vector3 =  Vector3.one;
       var c : Vector3;
       var rot: Quaternion;

       vect1 = transform.rotation * vect1;
       vect2 = rb.rotation * vect2;

       c = Vector3.Cross(vect1, vect2);

       rot.x = c.x;
       rot.y = c.y;
       rot.z = c.z;
       rot.w = Mathf.Acos(Vector3.Dot(vect1, vect2));

       vect1 = rot * vect1;

       vect1 *=400; // So we can see it;
  
       Debug.DrawLine (transform.position , transform.position+vect1, Color.red); // Should be pointing in the direction of the other transformation
 }

Open in new window

0
 
LVL 1

Assisted Solution

by:codevomit
codevomit earned 0 total points
ID: 35198077
This does what I need it to do

var rb : Transform;

function Update () {
       var vect1 : Vector3 =  Vector3.right;
       var vect2 : Vector3 =  Vector3.right;
	   var vect3 : Vector3;
       var c : Vector3;
       var rot: Quaternion;

       vect1 = transform.rotation * vect1;
       vect2 = rb.rotation * vect2;

       c = Vector3.Cross(vect1, vect2);

       rot.x = c.x;
       rot.y = c.y;
       rot.z = c.z;
       rot.w = Mathf.Acos(Vector3.Dot(vect1, vect2));

       vect3 = rot * Vector3.one;

	   vect1 *=10; // So we can see it;
       vect2 *=10; // So we can see it;
      // vect3 *=400; // So we can see it;
	   c *= 10;
	   vect3 *=2;
	   rigidbody.AddRelativeTorque(vect3);
	   
	   vect3 *=400; // So we can see it;
  
       Debug.DrawLine (transform.position , transform.position+vect3, Color.red); 
       Debug.DrawLine (transform.position , transform.position+vect1, Color.green); 
       Debug.DrawLine (rb.position , rb.position+vect2, Color.green); 
       Debug.DrawLine (transform.position , transform.position+c, Color.white); 
 }

Open in new window

0
 
LVL 1

Author Closing Comment

by:codevomit
ID: 35230026
The answer gave me a good direction but was not complete, my last comment should help fill in the blanks if anybody else is looking at this.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Random Variable 2 58
count7 challenge 12 130
Calculating Percentile Value inside Excel. 2 89
How to write an English digest paper 6 97
Complex Numbers are funny things.  Many people have a basic understanding of them, some a more advanced.  The confusion usually arises when that pesky i (or j for Electrical Engineers) appears and understanding the meaning of a square root of a nega…
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question