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:
Finding 3D Angle

Subject: Finding 3D Angle

From: Natalie Sin Hwee

Date: 9 Aug, 2010 10:20:09

Message: 1 of 11

Dear Mathworks,

I have two vectors in a 3D space.
By using:
 theta(bb,cc) = atan2(norm(cross(v1,v2)) , dot(v1,v2) );
but it does not give me information on directionality of the angle Theta.

Looking at cart2sph/pol,

How can i find the theta/phi and r between two 3dimensional vectors?

Thank you
Natalie

Subject: Finding 3D Angle

From: Frédéric Bergeron

Date: 9 Aug, 2010 12:28:07

Message: 2 of 11

Hey,

D'ont you could use the dot product?

u=[0 0 1]; v=[0 1 0];
theta=acosd(dot(u,v)/(norm(u)*norm(v)))

return 90 degrees, the angle between the two vectors in 3D...
Is that what you want?

Fred

Subject: Finding 3D Angle

From: Natalie Sin Hwee

Date: 9 Aug, 2010 14:04:04

Message: 3 of 11

"Frédéric Bergeron" <frederic.bergeron@logiag.com> wrote in message <i3os8m$58o$1@fred.mathworks.com>...
> Hey,
>
> D'ont you could use the dot product?
>
> u=[0 0 1]; v=[0 1 0];
> theta=acosd(dot(u,v)/(norm(u)*norm(v)))
>
> return 90 degrees, the angle between the two vectors in 3D...
> Is that what you want?
>
> Fred

Hiya fred,

I'm tryna find two angles:

1) x-y plane

2) perpendicular to x-y plane

so i can map the location of the 2nd vector

Thanks ^^
Natalie

Subject: Finding 3D Angle

From: Matt J

Date: 9 Aug, 2010 14:05:27

Message: 4 of 11

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i3okop$9n9$1@fred.mathworks.com>...
> Dear Mathworks,
>
> I have two vectors in a 3D space.
> By using:
> theta(bb,cc) = atan2(norm(cross(v1,v2)) , dot(v1,v2) );
> but it does not give me information on directionality of the angle Theta.
======

v1 and v2 span a plane that cuts R^3 into two half-spaces. In order to set up a system of quadrants in this plane, and define which quadrant theta belongs to, you need some way of deciding which half-space is up and which half-space is down. This will probably require a 3rd vector residing in one of the half-spaces, marking it as up or down.



> Looking at cart2sph/pol,
>
> How can i find the theta/phi and r between two 3dimensional vectors?
=======

What's unclear? cart2sph returns these angles explicitly, so can't you get the separation by simple subtraction?

Subject: Finding 3D Angle

From: Natalie Sin Hwee

Date: 10 Aug, 2010 11:22:03

Message: 5 of 11

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i3p1v7$cps$1@fred.mathworks.com>...
> "Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i3okop$9n9$1@fred.mathworks.com>...
> > Dear Mathworks,
> >
> > I have two vectors in a 3D space.
> > By using:
> > theta(bb,cc) = atan2(norm(cross(v1,v2)) , dot(v1,v2) );
> > but it does not give me information on directionality of the angle Theta.
> ======
>
> v1 and v2 span a plane that cuts R^3 into two half-spaces. In order to set up a system of quadrants in this plane, and define which quadrant theta belongs to, you need some way of deciding which half-space is up and which half-space is down. This will probably require a 3rd vector residing in one of the half-spaces, marking it as up or down.
>
>
>
> > Looking at cart2sph/pol,
> >
> > How can i find the theta/phi and r between two 3dimensional vectors?
> =======
>
> What's unclear? cart2sph returns these angles explicitly, so can't you get the separation by simple subtraction?

If i have a line spanning between:
a=[0.5, 0, 1];
b=[0, 0.5, 0];

how can i find the Theta and Phi in relation to the x-y Plane?

Thank you
Nataile

Subject: Finding 3D Angle

From: Roger Stafford

Date: 10 Aug, 2010 18:04:04

Message: 6 of 11

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i3rcor$lvh$1@fred.mathworks.com>...
> If i have a line spanning between:
> a=[0.5, 0, 1];
> b=[0, 0.5, 0];
>
> how can i find the Theta and Phi in relation to the x-y Plane?
>
> Thank you
> Nataile
- - - - - - - - - -
  I have carefully read each of your three postings in this thread, and I still don't understand what you are asking. You speak of a "Theta and Phi in relation to the x-y Plane". What precisely do you mean by that? Also you asked about an 'r' in the first post. I haven't the least idea what you mean by that.

  Two vectors pointing from the 3D origin to two points will determine a plane. This plane and the x-y plane have a certain dihedral angle between them. Also the planes' line of intersection makes a certain angle as measured from the x-axis. Are these your phi and theta, respectively?

  You will note that this is a very different question from determining the angle between the vectors. For example the dihedral angle can be found as the angle between the cross product of the vectors and the z-axis. If you took the cross product between this cross product and the z-axis you would have a vector along the line of intersection of the planes, and then you could find the angle between that and the x-axis. If you want specific formulas you need to be specific about what you are asking.

Roger Stafford

Subject: Finding 3D Angle

From: Natalie Sin Hwee

Date: 11 Aug, 2010 13:47:22

Message: 7 of 11

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i3s4ak$ou$1@fred.mathworks.com>...
> "Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i3rcor$lvh$1@fred.mathworks.com>...
> > If i have a line spanning between:
> > a=[0.5, 0, 1];
> > b=[0, 0.5, 0];
> >
> > how can i find the Theta and Phi in relation to the x-y Plane?
> >
> > Thank you
> > Nataile
> - - - - - - - - - -
> I have carefully read each of your three postings in this thread, and I still don't understand what you are asking. You speak of a "Theta and Phi in relation to the x-y Plane". What precisely do you mean by that? Also you asked about an 'r' in the first post. I haven't the least idea what you mean by that.
>
> Two vectors pointing from the 3D origin to two points will determine a plane. This plane and the x-y plane have a certain dihedral angle between them. Also the planes' line of intersection makes a certain angle as measured from the x-axis. Are these your phi and theta, respectively?
>
> You will note that this is a very different question from determining the angle between the vectors. For example the dihedral angle can be found as the angle between the cross product of the vectors and the z-axis. If you took the cross product between this cross product and the z-axis you would have a vector along the line of intersection of the planes, and then you could find the angle between that and the x-axis. If you want specific formulas you need to be specific about what you are asking.
>
> Roger Stafford

Hi Roger,

Sorry about that i will try to explain myself again. In a 3D space( x and y plane is e.g. the flat table on the base, and Z direction points upwards perpendicular to the 'table'/base)

I have two vectors A and B. A is pointing towards B.
I want to find the
1) Dihedral angle between Plane AB and Plane XY - and i think its called Phi.
2)X axis to Plane AB- and i think it is called Theta.

The notations are similar to the diagram found for help Sph2cart

I hope i have explained myself better.
Thank you

Natalie

Subject: Finding 3D Angle

From: Roger Stafford

Date: 11 Aug, 2010 21:36:02

Message: 8 of 11

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i3u9la$rgu$1@fred.mathworks.com>...
> Hi Roger,
>
> Sorry about that i will try to explain myself again. In a 3D space( x and y plane is e.g. the flat table on the base, and Z direction points upwards perpendicular to the 'table'/base)
>
> I have two vectors A and B. A is pointing towards B.
> I want to find the
> 1) Dihedral angle between Plane AB and Plane XY - and i think its called Phi.
> 2)X axis to Plane AB- and i think it is called Theta.
>
> The notations are similar to the diagram found for help Sph2cart
>
> I hope i have explained myself better.
> Thank you
>
> Natalie
- - - - - - - -
  Here's my try at getting your phi and theta for vectors A and B. Assume A and B are column vectors.

 C = cross(A,B); % Vector orthogonal to plane of A and B
 Z = [0;0;1]; % z-axis, normal to xy plane
 D = cross(Z,C); % D points along the planes' intersection line
 phi = atan2(norm(D),dot(Z,C)); % The angle between the planes
 theta = atan2(D(2),D(1)); % Angle counterclockwise from x-axis to D.

  You will notice that this answer depends on which order you take for vectors A and B. I base it on your statement "A is pointing towards B". Vector C is normal to the plane of vectors A and B. Vector Z is the z-axis vector and is normal to the xy plane. The dihedral angle phi between the plane of AB and the xy plane is the angle between their normals C and Z, resp. As computed here it will range from 0 to pi. Vector D lies in the xy plane and points along the intersection between the two planes. The angle theta is the angle measured counterclockwise in the xy plane from the x-axis to vector D, and as computed here it ranges from -pi to +pi.

  I hope these are the quantities you wanted. None of your four posts gives a non-ambiguous description of that. For example when you say "X axis to Plane AB", that can be interpreted in more than one way. I have interpreted it as above. When you say "Dihedral angle between Plane AB and Plane XY" you don't make clear which of two possible angles that might be, one the supplement of the other. As you see above I have made it depend on which way C is pointing, upwards or downwards, but that depends on whether A is considered first or B first. The value for theta depends on which way along the line of plane intersection D points. If you reverse D, that changes theta by pi.

  I hope this last discussion of the ambiguities involved would enable you to make the necessary corrections yourself if my interpretation is not in line with yours.

Roger Stafford

Subject: Finding 3D Angle

From: Natalie Sin Hwee

Date: 12 Aug, 2010 13:31:08

Message: 9 of 11

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i3v542$g20$1@fred.mathworks.com>...
> "Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i3u9la$rgu$1@fred.mathworks.com>...
> > Hi Roger,
> >
> > Sorry about that i will try to explain myself again. In a 3D space( x and y plane is e.g. the flat table on the base, and Z direction points upwards perpendicular to the 'table'/base)
> >
> > I have two vectors A and B. A is pointing towards B.
> > I want to find the
> > 1) Dihedral angle between Plane AB and Plane XY - and i think its called Phi.
> > 2)X axis to Plane AB- and i think it is called Theta.
> >
> > The notations are similar to the diagram found for help Sph2cart
> >
> > I hope i have explained myself better.
> > Thank you
> >
> > Natalie
> - - - - - - - -
> Here's my try at getting your phi and theta for vectors A and B. Assume A and B are column vectors.
>
> C = cross(A,B); % Vector orthogonal to plane of A and B
> Z = [0;0;1]; % z-axis, normal to xy plane
> D = cross(Z,C); % D points along the planes' intersection line
> phi = atan2(norm(D),dot(Z,C)); % The angle between the planes
> theta = atan2(D(2),D(1)); % Angle counterclockwise from x-axis to D.
>
> You will notice that this answer depends on which order you take for vectors A and B. I base it on your statement "A is pointing towards B". Vector C is normal to the plane of vectors A and B. Vector Z is the z-axis vector and is normal to the xy plane. The dihedral angle phi between the plane of AB and the xy plane is the angle between their normals C and Z, resp. As computed here it will range from 0 to pi. Vector D lies in the xy plane and points along the intersection between the two planes. The angle theta is the angle measured counterclockwise in the xy plane from the x-axis to vector D, and as computed here it ranges from -pi to +pi.
>
> I hope these are the quantities you wanted. None of your four posts gives a non-ambiguous description of that. For example when you say "X axis to Plane AB", that can be interpreted in more than one way. I have interpreted it as above. When you say "Dihedral angle between Plane AB and Plane XY" you don't make clear which of two possible angles that might be, one the supplement of the other. As you see above I have made it depend on which way C is pointing, upwards or downwards, but that depends on whether A is considered first or B first. The value for theta depends on which way along the line of plane intersection D points. If you reverse D, that changes theta by pi.
>
> I hope this last discussion of the ambiguities involved would enable you to make the necessary corrections yourself if my interpretation is not in line with yours.
>
> Roger Stafford

Dear Roger,

Thank you very much for your detailed help, i managed to interpret it into my code. Was wondering if i could obtain Theta from 0 to 2Pi (instead of -pi to +pi).


Thank you verymuch

Natalie

Subject: Finding 3D Angle

From: Roger Stafford

Date: 12 Aug, 2010 15:25:24

Message: 10 of 11

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i40t2s$f0u$1@fred.mathworks.com>...
> Dear Roger,
> Thank you very much for your detailed help, i managed to interpret it into my code. Was wondering if i could obtain Theta from 0 to 2Pi (instead of -pi to +pi).
> Thank you verymuch
>
> Natalie
- - - - - - - - - - -
  If you want to retain the theta angles from 0 to pi as they are at present and add 2*pi to those that are negative, you can change the last line to:

 theta = mod(atan2(D(2),D(1)),2*pi);

Roger Stafford

Subject: Finding 3D Angle

From: Natalie Sin Hwee

Date: 13 Aug, 2010 09:57:03

Message: 11 of 11

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i413p4$6og$1@fred.mathworks.com>...
> "Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i40t2s$f0u$1@fred.mathworks.com>...
> > Dear Roger,
> > Thank you very much for your detailed help, i managed to interpret it into my code. Was wondering if i could obtain Theta from 0 to 2Pi (instead of -pi to +pi).
> > Thank you verymuch
> >
> > Natalie
> - - - - - - - - - - -
> If you want to retain the theta angles from 0 to pi as they are at present and add 2*pi to those that are negative, you can change the last line to:
>
> theta = mod(atan2(D(2),D(1)),2*pi);
>
> Roger Stafford

Dear Roger,

Oh right! wow why didnt i think about that! Ure a star!! THANK YOU!!

Regards
Natalie

Tags for 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