PDA

View Full Version : Re: Calculation of 2D Angles ('CAST' problem)



Paolo De Leva
01-07-2003, 04:43 AM
Kris,

In the general case, to compute an angle correctly in 2D, indicating the
sign of the angle as well (i.e. whether it was measured clocwise or
counterclocwise) you do need to define two unit vectors and use dot and
cross products, as Feltner suggested. This method can be used to compute the
angle between two segments, as I'll explain later.

If you are just interested in an angle relative to the +x direction
(i.e. an absolute angular position), then you can just use the ATAN2(y,x)
function.

Before explaining how Feltner's method can be generalized, I would like
to simplify his explanation. Feltner's first statement is clear enough:

> If you define a horizontal unit vector (i) and a unit vector that points
> along the longitudinal axis of the segment (q), the dot (scalar) product
> function readily provides the angle between the two unit vectors. The
> sign of the Z component of the cross product of the two vectors then
> provides all the information necessary to interpret the angle
> information.

This explanation can be completed by simply specifying that:

1) the MAGNITUDE of the angle is given by the
arccosine of the dot product (i . q),

and

2) the SIGN of the angle is just the sign of the
Z component of the cross product (i X q).

There's nothing else. This method is simple and elegant, as you wanted.

Notice that it is not correct to state, as you did, that this method
implies a definition of a local coordinate system.
It just implies the definitions of two unit vectors in
the same (global or local, whatever you like) reference system.

The most interesting feature of this method is that it can be
generalized: the first vector (i) doesn't need to be horizontal! It could be
along the longitudinal axis of another segment (you may want to use a
different symbol, in this case, e.g. "p"). Using the dot product p.q and the
cross product pXq, you can compute the angle between two segments, rather
than the absolute angular position of a single segment.

Notice that the dot product will always give a value between 0 and +180
degrees. As for the meaning of the sign obtained as explained above,
a positive sign will mean that the shortest angle
(0
> A couple of subscribers (jim Ricahrds and Michael Feltner) have
> suggested using a local instead of global coordinate system. This
> strikes me as a potentially much more elegant solution.
>
> Since I am using Javascript, I will have to write functions for dot and
> cross product, but Michael Feltner has kindly given me the code for
> these:
>
> From:
> "Feltner, Michael"
>
> Chris
>
> If you define a horizontal unit vector (i) and a unit vector that points
> along the longitudinal axis of the segment (q), the dot (scalar) product
> function readily provides the angle between the two unit vectors. The
> sign
> of the Z component of the cross product of the two vectors then provides
> all
> the information necessary to interpret the angle information.
>
> For example, assume we have an orthogonal coordinate system with the X
> axis
> horizontal and pointing to the right, the Y axis is vertical, and Z is
> defined as X cross Y. Unit vectors i and j are associated with the X
> and Y
> axes, respectively. Vector S is defined as pointing from the proximal
> to
> the distal endpoint of the shank; thus q=S/magnitude(S). The angle
> (theta)
> between i and q is computed as:
>
> Theta = acos(i @ q), where @ is the dot product operation.
>
> Define a third vector, A, such that A = i X q, where X is the cross
> product
> operation.
>
> If the Z component of A is positive, you know that the distal endpoint
> has a
> higher (greater) Z coordinate that the proximal endpoint, thus the
> segment
> is located in either the first (theta < 90) or second (theta > 90)
> quadrant.
> If the Z component of A is negative, you know that the distal endpoint
> has a
> lower (smaller) Z coordinate that the proximal endpoint, thus the
> segment is
> located in either the fourth (theta < 90) or third (theta > 90)
> quadrant.
> At this point, assigning unique angle values based on quadrant location
> is
> trivial.
>
> Hope this helps,
>
> Michael
>
> Michael E. Feltner, Ph.D, FACSM
> Dept. of Sports Medicine
> Pepperdine University
> Malibu, CA 90263 USA
> EMAIL: michael.feltner@pepperdine.edu
> WEB: http://faculty.pepperdine.edu/mfeltner/
>
>
> SUBROUTINE VECTP(V1,V2,V3)
>
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCC
> CCC
> C
> C SUBROUTINE VECTP COMPUTES THE CROSS PRODUCT OF VECTOR V1 CROSS VECTOR
> V2.
> C THE ANSWER IS RETURNED IN VECTOR V3.
> C
>
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCC
> CCC
> IMPLICIT REAL*8 (A-H,O-Z)
> DIMENSION V1(3),V2(3),V3(3)
> V3(1)=(V1(2)*V2(3))-(V1(3)*V2(2))
> V3(2)=(V1(3)*V2(1))-(V1(1)*V2(3))
> V3(3)=(V1(1)*V2(2))-(V1(2)*V2(1))
> RETURN
> END
>
> SUBROUTINE SCALARP(Z1,Z2,DOTP)
>
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCC
> CCC
> C
> C SUBROUTINE SCALARP COMPUTES THE SCALAR PRODUCT OF VECTOR Z1 AND
> VECTOR
> Z2.
> C THE ANSWER IS RETURNED IN DOTP.
> C
>
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCC
> CCC
> REAL*8 DOTP,Z1(3),Z2(3)
> INTEGER*4 K
> DOTP=0.0
> DO 1 K=1,3
> DOTP=DOTP+(Z1(K)*Z2(K))
> 1 CONTINUE
> RETURN
> END
> --
> Dr. Chris Kirtley MD PhD
> Associate Professor
> Dept. of Biomedical Engineering
> Catholic University of America
> 620 Michigan Ave NE, Washington, DC 20064
> Tel. 202-319-6247, fax 202-319-4287
> Email: kirtley@cua.edu
> http://engineering.cua.edu/biomedical/faculty/kirtley
>
> ---------------------------------------------------------------
> To unsubscribe send SIGNOFF BIOMCH-L to LISTSERV@nic.surfnet.nl
> For information and archives: http://isb.ri.ccf.org/biomch-l
> ---------------------------------------------------------------
>

---------------------------------------------------------------
To unsubscribe send SIGNOFF BIOMCH-L to LISTSERV@nic.surfnet.nl
For information and archives: http://isb.ri.ccf.org/biomch-l
---------------------------------------------------------------