-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate_vector.pro
62 lines (55 loc) · 1.66 KB
/
rotate_vector.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;+
; NAME:
;
; rotate_vector
;
; PURPOSE:
; Given an axis or rotation, the angle (right hand screw motion), and
; the original (old) vector, this function rotates the old vector
; around the rotation axis by the amount of specified angle.
; geocentric. Please check here for background knowledge,
; https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation
;
; CATEGORY:
; Vector computation.
;
; INPUTS:
; rotationAxis
; : Three elements unit vector of the rotation axis ( cartesian coordinate)
; (float or double)
; Example, rotate around the Y axis, then the rotation axis is [ 0, 1, 0].
; oldVector
; : Three elements vector to be rotated ( cartesian coordinate)
; (float or double)
; angle
; : Angle of ratation in radian.
; (float or double)
;
; OPTIONAL INPUTS:
; newVector Three elements vector after rotation.
; (float or double)
;
; KEYWORD PARAMETERS:
;
;
;
; OUTPUTS:
; newVector Three elements vector after rotation.
; (float or double)
;
; EXAMPLE:
;
; MODIFICATION HISTORY:
; First written by Likun.Wang@noaa.gov from UMD/ESSIC/CICS on 06/2012
; Make some notes for GitHub release on 11/26/2018
;
;-
FUNCTION rotate_vector, rotationAxis, angle, oldVector
cosAngle = cos(angle) ;
sinAngle = sin(angle) ;
firstTerm = oldVector * cosAngle ;
secondTerm = CROSSP( oldVector, rotationAxis) * sinAngle ;
thirdTerm = (dot( oldVector, rotationAxis) * rotationAxis) * ( 1.0e0 - cosAngle) ;
newVector = firstTerm - secondTerm + thirdTerm ;
RETURN, newVector
END