I'm interested learning how quaternions simplify three-dimensional (3D) graphics programming, such as for a wireframe cube in C or C-style C++
(which I've programmed before, and is on my homepage for GCC C++ w/SDL,
maybe modifiable to C, and has a simple BSD-style license,) doing all
the details, i.e., not using libraries (except, perhaps put_pixel() and line(), not even some matrix library, let alone graphics ones doing it
all for you.)
So, I'd like to know, how can quaternions simplify this process? I
recall they're something like a scalar on some (x,y,z) but forgot how
that would seem to simplify any multiplication or iteration.
Rather than in one suggestion I was given, saying break this down into
more objects such as vertex vectors and a rotation matrix with twice as
many angles than I need, I'd still prefer to use an object matrix
(defining my cube's vertices,) and rotation matrices (and saw at least a couple different types, maybe still with several of each that could be multiplied,) but if there's a way to do either fewer matrix
multiplications,
I'm interested learning how quaternions simplify three-dimensional
(3D) graphics programming, such as for a wireframe cube in C or
C-style C++ (which I've programmed before, and is on my homepage for
GCC C++ w/SDL, maybe modifiable to C, and has a simple BSD-style
license,) doing all the details, i.e., not using libraries (except,
perhaps put_pixel() and line(), not even some matrix library, let
alone graphics ones doing it all for you.)
I.e., the only thing I'd want to use from C++ for this (since I'm
trying to learn more C and linear algebra) is in the case in C++ you
can set your matrix's values all at once, rather than I recall, in C,
I had to do one element at a time. So, I want to be able to comment
out that one-line assignment, and write C-style multiple lines, if I
want to save as a .C instead of .CC.
I combined the three standard 3x3 3D rotation matrices into one in
which I can input angles I want, then multiplied it by my 3x8 matrix
of the cube vertices (actually one by one, with a for-loop,) and after
doing perspective and displaying the cube, iterated through time (t)
to move the cube. But, I recall from a university math club lecture, quaternions already have (x,y,z) defined for all t with respect to
whatever 3D rotation angles you use.
So, I'd like to know, how can quaternions simplify this process? I
recall they're something like a scalar on some (x,y,z) but forgot how
that would seem to simplify any multiplication or iteration.
Rather than in one suggestion I was given, saying break this down into
more objects such as vertex vectors and a rotation matrix with twice
as many angles than I need, I'd still prefer to use an object matrix (defining my cube's vertices,) and rotation matrices (and saw at least
a couple different types, maybe still with several of each that could
be multiplied,) but if there's a way to do either fewer matrix multiplications, or not so much iteration, that would be a
benefit... is that what one could do with quaternions? Or, is there
some simpler way, that will still reduce the amount of code you need
to write, and amount of variables/objects you need to use, as well as
the calculations?
David (Darwin in USA code/math/graphics/art/music Demoscene) http://www.cwu.edu/~melikd/
On Sunday, August 20, 2017 at 6:58:21 AM UTC+2, David Melik wrote:
So, I'd like to know, how can quaternions simplify this process? I
recall they're something like a scalar on some (x,y,z) but forgot how
that would seem to simplify any multiplication or iteration.
Quaternions are useful if you need a compact representation of a 3D
rotation matrix. Given a normalized quaternion q, it's rather easy to determine a corresponding rotation matrix R
R = q2rot(q) (I won't bother defining q2rot)
And for every rotation matrix R there are two such quaternions:
q and -q. This q2rot functions has the following properties:
q2rot(q) = q2rot(-q) and
q2rot(a * b) = q2rot(a) * q2rot(b).
Given the last equality and the fact that multiplying quaternions is
cheaper than multiplying 3x3 rotation matrices, quaternions allow you
to efficiently multiply lots of 3D rotations together. So, if you
need to multiply lots of rotations, quaternions are going to be more efficient for that.
However, if you want to apply the resulting rotation to a collection
of points (like the vertices of your cube), you should probably
convert the quaternion back to a 3x3 rotation matrix because this
matrix representation is more efficient for such things in terms of
number of necessary floating point operations.
I think that answers your question?
(reply below is on Usenet and 'blind carbon copy' (BCC) to a listserv)
On 08/21/2017 05:12 AM, SG wrote:
On Sunday, August 20, 2017 at 6:58:21 AM UTC+2, David Melik wrote:
So, I'd like to know, how can quaternions simplify this process? I
recall they're something like a scalar on some (x,y,z) but forgot how
that would seem to simplify any multiplication or iteration.
Quaternions are useful if you need a compact representation of a 3D
rotation matrix. Given a normalized quaternion q, it's rather easy to
determine a corresponding rotation matrix R
R = q2rot(q) (I won't bother defining q2rot)
Not define... why? If, for example, quaternions (or anything) were
being described in a pure mathematics textbook, *everything* would be defined, probably full detail (unless left as an exercise, where at
least they'd define their terms.) It turns out I won't necessarily need definition now (if you see my reply to your question below,) but...
And for every rotation matrix R there are two such quaternions:
q and -q. This q2rot functions has the following properties:
q2rot(q) = q2rot(-q) and
q2rot(a * b) = q2rot(a) * q2rot(b).
Given the last equality and the fact that multiplying quaternions is
cheaper than multiplying 3x3 rotation matrices, quaternions allow you
to efficiently multiply lots of 3D rotations together. So, if you
need to multiply lots of rotations, quaternions are going to be more
efficient for that.
However, if you want to apply the resulting rotation to a collection
of points (like the vertices of your cube), you should probably
convert the quaternion back to a 3x3 rotation matrix because this
matrix representation is more efficient for such things in terms of
number of necessary floating point operations.
Ok, so apparently they don't really improve something as basic as
rotating a cube. So, if I made a larger or generalized 3D system, they could be useful.
For the cube I did, I combined my rotation matrices for the three angles myself, beforehand. So, it seems, I won't achieve anything more by
replacing that.
I think that answers your question?
Part of it (and all most important parts for now.) I still want to
learn quaternions for a 3D C or C-style C++ program, and now have a
better overview (not details)... but you've clarified, I should try a 3D thing they're more useful for, first, or just a calculation program. So,
I'll have to choose which way to continue, before any more detailed questions.
That's all for now on on Usenet from me.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 374 |
Nodes: | 16 (2 / 14) |
Uptime: | 141:39:21 |
Calls: | 7,958 |
Calls today: | 3 |
Files: | 13,011 |
Messages: | 5,814,073 |