Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can I determine a vector if I knew the angle between two vectors and the other vector in MATLAB

Subject: How can I determine a vector if I knew the angle between two vectors and the other vector in MATLAB

From: Tran Quang Dat

Date: 1 Dec, 2011 02:28:08

Message: 1 of 7

Hi there, I have two vectors, and I knew a vector and the angle between two vectors. I am wondering how do I get the another vector in Matlab.

Thank You very much.
 Tran Quang Dat

Subject: How can I determine a vector if I knew the angle between two

From: Rune Allnor

Date: 1 Dec, 2011 02:53:07

Message: 2 of 7

On 1 Des, 03:28, "Tran Quang Dat" <tranda...@gmail.com> wrote:
> Hi there, I have two vectors, and I knew a vector and the angle between two vectors. I am wondering how do I get the another vector in Matlab.

What do you mean?

First of all, you need to specify the dimensions
of the vectors. In 3D and above, there are infinitely
many unit vectors u at angle theta with some
reference vector v.

If you know one 2D vector u and want to find a vector
v at an angle theta with u, you only need to rotate
u by theta.

If you know two 2D vectors u and v, and want to
find a third vector w at specified angles with u
and w, things might get very tricky, as you will
need to solve triginometric equations for theta.

Rune

Subject: How can I determine a vector if I knew the angle between two

From: Tran Quang Dat

Date: 1 Dec, 2011 03:16:08

Message: 3 of 7

Rune Allnor <allnor@tele.ntnu.no> wrote in message <e1475487-6bfd-4ed0-81da-c576db6f35b0@q9g2000yqe.googlegroups.com>...
> On 1 Des, 03:28, "Tran Quang Dat" <tranda...@gmail.com> wrote:
> > Hi there, I have two vectors, and I knew a vector and the angle between two vectors. I am wondering how do I get the another vector in Matlab.
>
> What do you mean?
>
> First of all, you need to specify the dimensions
> of the vectors. In 3D and above, there are infinitely
> many unit vectors u at angle theta with some
> reference vector v.
>
> If you know one 2D vector u and want to find a vector
> v at an angle theta with u, you only need to rotate
> u by theta.
>
> If you know two 2D vectors u and v, and want to
> find a third vector w at specified angles with u
> and w, things might get very tricky, as you will
> need to solve triginometric equations for theta.
>
> Rune

Thank You very much for Your help.
My problem is in 2D, and I need to find a vector v at an angle theta with u as your prediction. So, could you please tell me how can I rotate u by theta.
Once again, thank you very much.
Tran Quang Dat

Subject: How can I determine a vector if I knew the angle between two

From: Roger Stafford

Date: 1 Dec, 2011 03:50:09

Message: 4 of 7

"Tran Quang Dat" wrote in message <jb6rho$kbe$1@newscl01ah.mathworks.com>...
> My problem is in 2D, and I need to find a vector v at an angle theta with u as your prediction. So, could you please tell me how can I rotate u by theta.
> Once again, thank you very much.
> Tran Quang Dat
- - - - - - - -
  There will be two solutions, v1 and v2:

  a = atan2(u(2),u(1)); % Angle w.r. x-axis
  v1 = [cos(a+theta),sin(a+theta)]; % Rotate plus theta
  v2 = [cos(a-theta),sin(a-theta)]; % Rotate minus theta

Both v1 and v2 will be unit vectors.

Roger Stafford

Subject: How can I determine a vector if I knew the angle between two

From: Roger Stafford

Date: 1 Dec, 2011 04:10:09

Message: 5 of 7

"Roger Stafford" wrote in message <jb6thh$pu3$1@newscl01ah.mathworks.com>...
> There will be two solutions, v1 and v2:
>
> a = atan2(u(2),u(1)); % Angle w.r. x-axis
> v1 = [cos(a+theta),sin(a+theta)]; % Rotate plus theta
> v2 = [cos(a-theta),sin(a-theta)]; % Rotate minus theta
>
> Both v1 and v2 will be unit vectors.
>
> Roger Stafford
- - - - - - - - -
  The computation may be a little faster if you do it this way:

 c = cos(theta); s = sin(theta); n = norm(u);
 v1 = [u(1)*c-u(2)*s,u(2)*c+u(1)*s]/n;
 v2 = [u(1)*c+u(2)*s,u(2)*c-u(1)*s]/n;

Roger Stafford

Subject: How can I determine a vector if I knew the angle between two

From: Tran Quang Dat

Date: 1 Dec, 2011 05:39:09

Message: 6 of 7

"Roger Stafford" wrote in message <jb6un1$t6f$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jb6thh$pu3$1@newscl01ah.mathworks.com>...
> > There will be two solutions, v1 and v2:
> >
> > a = atan2(u(2),u(1)); % Angle w.r. x-axis
> > v1 = [cos(a+theta),sin(a+theta)]; % Rotate plus theta
> > v2 = [cos(a-theta),sin(a-theta)]; % Rotate minus theta
> >
> > Both v1 and v2 will be unit vectors.
> >
> > Roger Stafford
> - - - - - - - - -
> The computation may be a little faster if you do it this way:
>
> c = cos(theta); s = sin(theta); n = norm(u);
> v1 = [u(1)*c-u(2)*s,u(2)*c+u(1)*s]/n;
> v2 = [u(1)*c+u(2)*s,u(2)*c-u(1)*s]/n;
>
> Roger Stafford

Thank you very much
Tran Quang Dat

Subject: How can I determine a vector if I knew the angle between two

From: Roger Stafford

Date: 1 Dec, 2011 07:16:08

Message: 7 of 7

"Roger Stafford" wrote in message <jb6un1$t6f$1@newscl01ah.mathworks.com>...
> c = cos(theta); s = sin(theta); n = norm(u);
> v1 = [u(1)*c-u(2)*s,u(2)*c+u(1)*s]/n;
> v2 = [u(1)*c+u(2)*s,u(2)*c-u(1)*s]/n;
- - - - - - - - -
  It would have been more appropriate to express your rotations in terms of matrices since that is what matlab is all about. Let u, v1, and v2 be column vectors (with x-coord. first and y-coord. second.)

 c = cos(theta); s = sin(theta);
 R1 = [c -s;s c]; R2 = [c s;-s c];
 v1 = R1*u; v2 = R2*u;

(Note: these leave the lengths of v1 and v2 the same as that of u.)

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us