HERE is a way to track rotation separately without modifying the original data, and WITHOUT USING TRIG:

A rotation is {w,x,y,z} (a quaternion), such that {x,y,z} is an axis and w is the angle of rotation.

A point is {x,y,z}.

To rotate a rotation {w1,x1,y1,z1} by another rotation {w2,x2,y2,z2}, the result is:

{ w1*w2 - x1*x2 - y1*y2 - z1*z2,

w1*x2 + w2*x1 + y1*z2 - z1*y2,

w1*y2 + w2*y1 + z1*x2 - x1*z2,

w1*z2 + w2*z1 + x1*y2 - y1*x2 }

The inverse of a rotation (used in the next equation) is:

{ w * 1/(w*w + x*x + y*y + z*z),

x * -1/(w*w + x*x + y*y + z*z),

y * -1/(w*w + x*x + y*y + z*z),

z * -1/(w*w + x*x + y*y + z*z) }

...and finally, to rotate a point by the rotation, do this:

1) make a new rotation like this (1=rotation, 2=point):

{ -x1*x2 - y1*y2 - z1*z2,

w1*x2 + y1*z2 - z1*y2,

w1*y2 + z1*x2 - x1*z2,

w1*z2 + x1*y2 - y1*x2 }

2) rotate that new rotation by its inverse

3) the rotated point is {x,y,z} from that new rotation (last 3 parts)

You always keep track of a rotation, and you only rotate a COPY of whatever you are using as the model.

EXAMPLES:

A rotation 5 degrees around the X-axis looks like: {5*180/PI, 1, 0, 0}

A rotation 5 degrees around the Y-axis looks like: {5*180/PI, 0, 1, 0}

A rotation 5 degrees around the Z-axis looks like: {5*180/PI, 0, 0, 1}

In other words, a rotation W degrees around the axis described by the point {X,Y,Z} looks like: {W*180/PI, X, Y, Z}

Note that rotation is in radians; degrees are converted to radians by going degrees*180/PI.

You can use anything besides degrees; just multiply it by half of whatever a full rotation is and multiply by PI (or a full rotation and 2*PI)

From what I can tell, quaternions tell what axis to rotate around to get to a position, rather than specifying what axis to rotate TO (that method is inaccurate, since you may need to rotate around that axis; that's two rotations!}. I don't know WHY quaternions work, they just do; the only draw back of quaternions is that they are supposed to be impossible to visualize what rotation it represents, or how it even finds the correct axis and stuff.

A quaternion is actually a complex number like a+bi, but it consists of

a + bi + cj + dk. Here are some of its properties:

i^2 = j^2 = k^2 = ijk = -1

ij = -ji = k

ik = -ki = j

jk = -kj = i

It's hard to understand.

Quaternions can also be used in various other applications like physics

It looks like you're new here. If you want to get involved, click one of these buttons!

- 140.8K All Categories
- 103.6K Programming Languages
- 6.4K Assembler Developer
- 401 Assembly Code Share
- 239 Getting started in assembly
- 4.6K x86 Assembly
- 1.9K Basic
- 97 Qbasic
- 39.9K C and C++
- 5.6K Beginner C/C++
- 330 C/C++ on Linux/Unix
- 450 C/C++ Windows API
- 522 C++ Builder
- 253 C++ Game Development
- 3.3K C++ MFC
- 103 C++.NET
- 404 Visual C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 334 Advanced Delphi
- 360 Delphi beginners
- 4 Haskell
- 9.7K Java
- 56 Enterprise JavaBeans
- 1.3K Java Beginners
- 304 Java Server Pages
- 4.1K Pascal
- 1.3K Perl
- 11 Perl 6
- 2K PHP
- 546 Python
- 37 Ruby
- 4.4K VB.NET
- 258 Advanced VB.Net
- 1.6K VBA
- 20.8K Visual Basic
- 767 Access databases and VB
- 831 Advance Visual Basic
- 1.2K Beginner VB
- 2.6K Game programming
- 315 Console programming
- 90 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 279 3D Graphics
- 129 DirectX
- 125 OpenGL
- 740 Computer Hardware
- 9 Cooling & Overclocking
- 3.4K Database & SQL
- 1.1K Access
- 91 ADO Programming
- 288 MySQL
- 358 Oracle
- 440 SQL-Server
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 25 DirectSound
- 257 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 603 Jobs Wanted
- 209 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 22 .NET WEB-Services
- 129 .NET WinForms
- 14 .NET XML
- 50 ADO.NET
- 142 C# & VB.NET School Support
- 3.4K Miscellaneous
- 4 Join the Team
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 621 Off topic board
- 200 Mobile & Wireless
- 72 Android
- 126 Palm Pilot
- 338 Multimedia
- 154 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 27 Cloud Computing
- 1 Witsbits Go Cloud
- 53 FreeBSD
- 1.7K LINUX programming
- 1 Awk scripting
- 332 Linux Support
- 0 Sed scripting
- 370 MS-DOS
- 0 Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 177 COM/DCOM
- 61 Networking And Security
- 17 Windows 2003 Server
- 6 Windows Vista
- 176 Windows XP
- 939 Software Development
- 416 Algorithms
- 68 Object Orientation
- 24 RUP & UML
- 91 Project Management
- 95 Quality & Testing
- 268 Security
- 63 Evil Scripting
- 81 Hacking
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 4 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 131 Mobile Internet & Messaging
- 211 Wireless development
- 2.2K JavaScript
- 37 JQuery
- 304 WEB Servers
- 153 Apache
- 79 IIS
- 150 WEB-Services / SOAP

## Comments

Google: "CS184: Using Quaternions to Represent Rotation". It tells what operations to use and stuff, but it gets very confusing where it explains how to do the operations (I had to get that from the next site)

Google: "OOP Meets Algebra". This guy made a quaternion class to represent the rotation for a cube that rotates along 3 rotations that you can toggle on/off. (I had to go through function after function to pull out the correct equations).

In short, to rotate a point P by a quaternion q, you go q*P*q^-1 and ignore the w in the result; to rotate a rotation, just go q1*q2 (note, this is NOT the same as q2*q1!)

C = a + j*b (the classical form)

or in a bit more geometrical form as

C = A*cos(t+Phi) or C = A*cos(t) + j*sin(t).

pow(E,j*t*w) = cos(w*t) + j*sin(w*t) (w is greek omega )

So you can represent a complex number with a length and a angle as well.By converting a point in 2d-space to a complex number you can do rotation(angle-calculations) and possibly scaling(length-calculations,but im not sure with this).

If I remember right a quaternion has just more imaginar axis than complex numbers.so there should be ways to convert the classical form of a quaternion to one with angles and lengths.

Its highly possible (plz anybody correct me if Im wrong) that this library performs the multiplication at least one time with a cos/sin operation because each imaginary axis must stay independent from the others.

I think a better (and more understandable?) way for vector-calculations are the good,old school matrices.But its always good,to get new inspiration to see other ways to do the job

There is NO TRIG involved. You just create those new arrays using those formulas, and it should work.

complex number CAN be written in a trigonometric way and the separate multiplacation of real and imaginary parts are a bit similar to matrices with angles.

Euler-Identity:

POW(E,j*x) = cos(x) + j*sin(x) = C

C is a complex number with the length 1 and an angle depending on x.

I will check a math-book about quaterions tommorow,its realy interesting.But I think they are mathematicly nearly the same as a 4x4-matrices with trig.-ops.

Complex numbers,however,have a lot to do with angles and trigonometry,they can be used to describe harmonical functions (sin/cos) with the E-function and in some other ways.

C1*C2 can be done in a lot of different ways,eachone giving a correct result.however,some ways are easier than other

Quaternions are pretty old in 3D games. The main reason for them is to avoid gimbal lock.

The link below pretty much answers most quaternions questions. Secondly if you can acquire Game Programming Gems 1, read the info about quaternions, it also show you mathematical formulas and derivations to a certain extent.

http://www.flipcode.com/documents/matrfaq.html

And umm to do rotation, sin, cos functions are pretty much used in quaternions.

http://www.flipcode.com/documents/matrfaq.html#Q56

http://www.flipcode.com/documents/matrfaq.html#Q57

And if you use DirectX, it has quaternion functions in its API. Creating them however is no problem.

: NO THANKS to anybody out there, I have FINALLY derived a few SIMPLE equations to handle 3D abstract rotation. I had to take a quaternion class (class = object definition) that somebody made and go through it for an hour to pull out a couple equations.

:

: HERE is a way to track rotation separately without modifying the original data, and WITHOUT USING TRIG:

:

: A rotation is {w,x,y,z} (a quaternion), such that {x,y,z} is an axis and w is the angle of rotation.

:

: A point is {x,y,z}.

:

: To rotate a rotation {w1,x1,y1,z1} by another rotation {w2,x2,y2,z2}, the result is:

:

: { w1*w2 - x1*x2 - y1*y2 - z1*z2,

: w1*x2 + w2*x1 + y1*z2 - z1*y2,

: w1*y2 + w2*y1 + z1*x2 - x1*z2,

: w1*z2 + w2*z1 + x1*y2 - y1*x2 }

:

: The inverse of a rotation (used in the next equation) is:

:

: { w * 1/(w*w + x*x + y*y + z*z),

: x * -1/(w*w + x*x + y*y + z*z),

: y * -1/(w*w + x*x + y*y + z*z),

: z * -1/(w*w + x*x + y*y + z*z) }

:

: ...and finally, to rotate a point by the rotation, do this:

:

: 1) make a new rotation like this (1=rotation, 2=point):

: { -x1*x2 - y1*y2 - z1*z2,

: w1*x2 + y1*z2 - z1*y2,

: w1*y2 + z1*x2 - x1*z2,

: w1*z2 + x1*y2 - y1*x2 }

:

: 2) rotate that new rotation by its inverse

: 3) the rotated point is {x,y,z} from that new rotation (last 3 parts)

:

: You always keep track of a rotation, and you only rotate a COPY of whatever you are using as the model.

:

: EXAMPLES:

: A rotation 5 degrees around the X-axis looks like: {5*180/PI, 1, 0, 0}

: A rotation 5 degrees around the Y-axis looks like: {5*180/PI, 0, 1, 0}

: A rotation 5 degrees around the Z-axis looks like: {5*180/PI, 0, 0, 1}

: In other words, a rotation W degrees around the axis described by the point {X,Y,Z} looks like: {W*180/PI, X, Y, Z}

:

: Note that rotation is in radians; degrees are converted to radians by going degrees*180/PI.

:

: You can use anything besides degrees; just multiply it by half of whatever a full rotation is and multiply by PI (or a full rotation and 2*PI)

:

: From what I can tell, quaternions tell what axis to rotate around to get to a position, rather than specifying what axis to rotate TO (that method is inaccurate, since you may need to rotate around that axis; that's two rotations!}. I don't know WHY quaternions work, they just do; the only draw back of quaternions is that they are supposed to be impossible to visualize what rotation it represents, or how it even finds the correct axis and stuff.

:

: A quaternion is actually a complex number like a+bi, but it consists of

: a + bi + cj + dk. Here are some of its properties:

:

: i^2 = j^2 = k^2 = ijk = -1

: ij = -ji = k

: ik = -ki = j

: jk = -kj = i

:

: It's hard to understand.

: Quaternions can also be used in various other applications like physics

:

Sorry, but I cannot understand...

The code you posted is not so different from what I had proposed you here:

http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=41&MsgID=228549

In fact all the quaternions equations you wrote subtend trigonometry and I cannot believe you understood quaternions (that are

4-dimensional vectors) and you don't understand trigonometry.

And, even if you don't understand trig and don't know how sin and cos work, using the equation I gave you you can do the same things much faster.

Btw, take a look here: http://www.gamasutra.com/features/19980703/quaternions_01.htm

nICO

[hr]

[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

JOHN KEATS