python


Camera rotation matrix


I am trying to raytrace a video. For that matter, I need the camera roation matrix for every frame, in world coordinates. The camera is at the origin. There are no translation.
I have the trajectory of the camera as changes in rotation for every frame.
So for every frame, I have three values (roll, yaw, pitch) that describe how much the camera should rotate from this frame to the next. These rotations are to be understand in the camera coordinate system.
How do I compute the world coordinate rotation matrices for the frames?
What I tried:
def rot_x(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[1,0,0], [0, cosa, -sina], [0, sina, cosa]])
def rot_y(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, 0, sina], [0,1,0], [-sina, 0, cosa]])
def rot_z(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, -sina, 0], [sina, cosa, 0], [0,0,1]])
matrices = [initial_rot]
for pitch, yaw, roll in frames_data:
rx = rot_x(pitch)
ry = rot_y(yaw)
rz = rot_z(roll)
last_matrix = matrices[-1]
matrices.append(last_matrix.T.dot(rx).dot(ry).dot(rz))
(Since last_matrix should be orthonormal, so the inverse of it should be the transpose).
However, something is horribly wrong, the rendered video just flickers in the y dimension. I am sure there is something wrong with the math here..

The order of the matrix multiplications matters. Applying another rotation should be done by left-multiplying (assuming a standard convention).
Since this is simply composition multiple rotations, there should not be any need to inverse the last rotation.
The complete rotation that should be computed for frame N is:
R_n = R(yaw_n, pitch_n, roll_n) R_{n - 1} R_{n - 2} ... R_1 R_0
with:
R_0: the initial rotation (i.e. initial_rot)
R_n: the complete rotation for the frame N
R(yaw_n, pitch_n, roll_n): the rotation derived from the yaw / pitch / roll values applied between frame N - 1 and N (i.e. rx.dot(ry).dot(rz))
Hence the last line in the code excerpt should instead be:
rotation = rx.dot(ry).dot(rz)
matrices.append(rotation.dot(last_matrix))


Related Links

Listening for specific data whilst using threading
How to import shared libraries created with numba export using ctypes?
Passing vectors and params from Python to R functions
Managing Autogenerated Indexes
Get file path from askopenfilename function in Tkinter
How to read a json-dictionary type file with pandas?
mplot3d python incompatible dimensions error
Is it normal for pygtk library download with macports to take a long time and print 33000 lines to terminal?
List out of range
Getting AttributeError Message when trying to close a file
sklearn LinearRegression reports error
Yapsy throws TypeError on init, missing arguments on init
Using or avoiding a class for credentials in a Python API; what is most Pythonic?
Synchronize pool of workers - Python and multiproccessing
Python: Matching/Substitution on multiple patterns
getting UnboundLocalError: local variable referenced before assignment error

Categories

HOME
arrays
spring
redis
google-tag-manager
wxwidgets
decorator
memory-leaks
cocos2d-x-3.0
transparent
matplotlib
orientation
ext.net
internet-explorer-11
shader
openwrt
cakephp-2.9
google-shopping
nuxt.js
multiple-monitors
sendkeys
sql-tuning
alfresco-share
pyyaml
flexlm
richfaces
http-method
branch
unpack
xilinx-ise
pcre
jboss5.x
construct-2
hotmail
data-extraction
rhomobile
salesforce-chatter
node-horseman
remote-server
autocompletetextview
liquid-xml
readfile
socketscan
taglib
spring-bean
stress-testing
fastq
asmx
bids
proof
nstouchbar
jenkins-jira-trigger
multi-agent
slot
bettercms
restivejs
picasa
chessboard.js
acm
p-np
sem
subversion-edge
low-level
qtestlib
dalekjs
adaptive-compression
code-testing
wss
roxygen
angulartics
vertical-rhythm
installshield-2009
ftp4j
lame
client-side-scripting
dynamics-ax-2009
database-permissions
process-monitor
gdataxml
lync-server-2010
xgettext
sunspot-rails
symfony-2.0
fotoware
wcf-web-api
parameterization
gjs
makefile-project
surf
galaxy-tab
adsl
ruby-debug
email-spec
chatroom
surefire
code-design
internals
usergroups





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm