PDA

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

Dr. Chris Kirtley
12-19-2002, 04:07 AM
Dear all,

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