Skip to content

Commit

Permalink
2015.05.12 Example and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
minchulmando committed May 12, 2015
1 parent 7bd3eb1 commit dd85b28
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ImRotLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#--------------------------------------------------------------------------------

# import the basic librarires
from math import atan2, cos, sin, sqrt
from math import atan2, cos, sin, sqrt, pi
from numpy import float64, hypot, zeros, flatnonzero, array

# Makes 3D rotation matrices from axis/angle
def Fn_AxisAngle2RotMat(matrix, axis, angle):
# Trig factors.
ca = cos(angle)
sa = sin(angle)
ca = cos(pi*angle/180)
sa = sin(pi*angle/180)
C = 1 - ca

# Depack the axis.
Expand Down Expand Up @@ -84,7 +84,7 @@ def Fn_RotMat2AxisAngle(matrix):
# Angle.
r = hypot(axis[0], hypot(axis[1], axis[2]))
t = matrix[0,0] + matrix[1,1] + matrix[2,2]
theta = atan2(r, t-1)
theta = 180*atan2(r, t-1)/pi

# Normalise the axis.
axis = axis / r
Expand Down
55 changes: 55 additions & 0 deletions Main_ImRotLibrary_Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#--------------------------------------------------------------------------------
# Image transformation and filtering functions of Computer Vision class (2015-1)
#
# Minchul Lee: Initial code generation (2015.05.07)
# Minchul Lee: Debug (2015.05.12)
#--------------------------------------------------------------------------------

# Import libraries
import numpy as np
import ImRotLibrary as IMRot

#------------------------------------------------------------------------
# Axis, angle to Rotation matrix representation example
print '\n1) Axis, angle to Rotation matrix representation example'
angle = 90.0 # degree
axis = np.float64(np.array([1,0,0])) # axis
RotMat = np.zeros((3,3)) # zero matrix initializaition
print 'Angle: ', angle, ' [deg], Axis: ', axis


# functino run
IMRot.Fn_AxisAngle2RotMat(RotMat, axis, angle)

print 'Rotation matrix:\n', RotMat
#------------------------------------------------------------------------

#------------------------------------------------------------------------
# Rotation matrix to Axis, angle representation example
print '\n2) Rotation matrix to Axis, angle representation example'
print '[Info] Upeer rotation matrix is used for this exmaple\n'
#function run
axis_RotMat, angle_RotMat = IMRot.Fn_RotMat2AxisAngle(RotMat)

print 'Axis:', axis_RotMat, ', Angle: ', angle_RotMat, '[deg]'
#------------------------------------------------------------------------

#------------------------------------------------------------------------
# quaternian to Rotation matrix representation example
print '\n3) quaternian to Rotation matrix representation example'
Quat = np.float64(np.array([np.sqrt(2)/2, 0, 0, -np.sqrt(2)/2]))
print 'Quaternion: ', Quat
RotMat_Quat = np.zeros((3,3))

IMRot.Fn_Quat2RotMat(Quat,RotMat_Quat)
print 'Rotation matrix:\n', RotMat_Quat
#------------------------------------------------------------------------

#------------------------------------------------------------------------
# Rotation matrix to quaternian representation example
print '\n4) Rotation matrix to quaternian representation example'
print '[Info] Upeer rotation matrix is used for this exmaple\n'

Quat_RotMat = IMRot.Fn_RotMat2Quat(RotMat)
print 'Quaternion: ', Quat_RotMat
#------------------------------------------------------------------------

0 comments on commit dd85b28

Please sign in to comment.