You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

[Python 2.7] Quaternion Arithmetic Program

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/PC, Mac & Vintage Computers publicado por u/Thecoder1998 April 18, 2015, 04:41:58 PM
Hi guys, i'm currently learning how to program in Python and i've made a neat little script which can do arithmetic with quaternions  :)

from numpy import matrix
def quaternion(a,b,c,d):
    u = matrix('1.,0.,0.,0.;0.,1.,0.,0.;0.,0.,1.,0.;0.,0.,0.,1.')
    i = matrix('0.,1.,0.,0.;-1.,0.,0.,0.;0.,0.,0.,-1.;0.,0.,1.,0.')
    j = matrix('0.,0.,1.,0.;0.,0.,0.,1.;-1.,0.,0.,0.;0.,-1.,0.,0.')
    k = matrix('0.,0.,0.,1.;0.,0.,-1.,0.;0.,1.,0.,0.;-1.,0.,0.,0.')
    q = a*u+b*i+c*j+d*k
    return q
def printquaternion(q):
    a = q.item(0,0)
    b = q.item(0,1)
    c = q.item(0,2)
    d = q.item(0,3)
    q = "%s+%si+%sj+%sk"%(a,b,c,d)
    print q

here is a screenshot

Last Edit: April 18, 2015, 04:43:58 PM by Thecoder1998
Inicia sesión o crea una cuenta para dejar un comentario
u/Snektron April 18, 2015, 08:40:13 PM
Maybe you could make it parse a quaterion from a string too, that would be cool
u/Duke "Tape" Eiyeron April 20, 2015, 04:19:32 PM
I forgot how it's nice to print formatted strings on python as in C but easier.
Start a Discussion

b/PC, Mac & Vintage Computers

Computer programming discussion and project showcase

132
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal