PDA

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



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

Sorry - I hit some sort of key combination which sent my message before
I intended! There were a couple more replies. I thought you might also
like to see the code Ray came up with back in 1995, which I have been
using all these years. It works beautifully (for any motion whatsoever)
but seemed, as I say, to be somewhat laborious. If anyone can suggest
how it could be streamlined, I will distribute the improved version. I
think this would be a nice addition to the ISB software site. Lastly, a
personal bette-noir: I do wish people would avoid suggesting MATLAB
solutions, since these often depend on MATLAB-specific routines, and are
of course useless for programming in other languages. (I now await the
flames...)

Chris

Public Function Sector(xProximal As Integer, yProximal As Integer,
xDistal As Integer, yDistal As Integer) As Integer
'finds which sector (CAST quadrant) the segment lies in - also works if
vertical or horizontal
Dim segment As Integer
If yProximal = yDistal And xProximal < xDistal Then
segment = 180
Sector = 1
ElseIf yProximal > yDistal And xProximal < xDistal Then
segment = 180 - (180 * (Atn((yProximal - yDistal) /
(xDistal - xProximal)))) / 3.142
Sector = 2
ElseIf yProximal > yDistal And xProximal = xDistal Then
segment = 90
Sector = 3
ElseIf yProximal > yDistal And xProximal > xDistal Then
segment = 57 * (Atn((yProximal - yDistal) / (xProximal -
xDistal)))
Sector = 4
ElseIf yProximal < yDistal And xProximal < xDistal Then
segment = (57 * Atn((yDistal - yProximal) / (xDistal -
xProximal))) + 180
Sector = 5
ElseIf yProximal < yDistal And xProximal = xDistal Then
segment = 270
Sector = 6
ElseIf yProximal < yDistal And xProximal > xDistal Then
segment = 360 - (57 * (Atn((yDistal - yProximal) /
(xProximal - xDistal))))
Sector = 7
ElseIf yProximal = yDistal And xProximal > xDistal Then
segment = 0
Sector = 8
ElseIf yProximal = yDistal And xProximal = xDistal Then
segment = 0
Sector = 9
End If
SegmentAngle.AddItem segment
End Function

Public Function joint(proximalAngle As Integer, proximalSector As
Integer, distalAngle As Integer, distalSector As Integer) As Integer
'finds included joint angle given angle of the CoM either side
Select Case distalSector
Case 1
joint = proximalAngle

Case 2
Select Case proximalSector

Case 7
If proximalAngle - distalAngle = proximalAngle Then
joint = 360 - (distalAngle - 180) - proximalAngle
ElseIf distalAngle - 180 < proximalAngle Then
joint = proximalAngle - (distalAngle - 180)
End If
Case 8
joint = 360 - (270 - distalAngle)
Case Else
joint = proximalAngle - (distalAngle - 180)
End Select

Case 6
Select Case proximalSector
Case 4
joint = 360 - (90 - proximalAngle)
Case 8
joint = distalAngle - proximalAngle
Case Else
joint = proximalAngle - 90
End Select

Case 7
Select Case proximalSector
Case 2
If distalAngle - 180 < proximalAngle Then
joint = proximalAngle - 90 - (distalAngle - 270)
ElseIf distalAngle - 180 >= proximalAngle Then
JointAngle = 360 - (90 - (360 - distalAngle) - (proximalAngle - 90))
End If

Case 1
joint = 180 - (distalAngle - proximalAngle)
Case 3, 8
joint = (distalAngle - 180) + proximalAngle
Case 4
joint = (360 - distalAngle) + (180 + proximalAngle)
Case Else
joint = (360 - distalAngle) + (proximalAngle - 180)
End Select

Case 8
joint = distalAngle + proximalAngle

Case Else
joint = -9999 'undefined (should never happen!)
End Select
End Function
--
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
---------------------------------------------------------------