From: "Natalie Sin Hwee " <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Finding 3D Angle
Date: Thu, 12 Aug 2010 13:31:08 +0000 (UTC)
Organization: Imperial College
Lines: 42
Message-ID: <i40t2s$f0u$>
References: <i3okop$9n9$> <i3p1v7$cps$> <i3rcor$lvh$> <i3s4ak$ou$> <i3u9la$rgu$> <i3v542$g20$>
Reply-To: "Natalie Sin Hwee " <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1281619868 15390 (12 Aug 2010 13:31:08 GMT)
NNTP-Posting-Date: Thu, 12 Aug 2010 13:31:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2069448
Xref: comp.soft-sys.matlab:661395

"Roger Stafford" <> wrote in message <i3v542$g20$>...
> "Natalie Sin Hwee " <> wrote in message <i3u9la$rgu$>...
> > 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