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

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 629 Off topic board
- 217 Mobile & Wireless
- 89 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 152 WEB-Services / SOAP

Shkaboinka
Member Posts: **79**

in 3D Graphics

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

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

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

79Google: "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!)

348C = 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

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

348complex 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

642Quaternions 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

:

349Sorry, 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