[linear algebra] - question to David Abrahams

Hello, Not so long ago you have mentioned that you are working on a linear algebra library. I'm very interested in this topic, because I'm using such library in my project. I have looked into the vault but couldn't find this library. Can we have a sneak peek? Questions: 1. will your library provide functions useful when working with small vectors like: cross_product(), dot_product(), normalize() (scale vector so its length()==1), norm() (returns squared length), length(), etc... ? 2. will your library allow Boost.Quaternions to be extended in a way that those two libraries together will be useful for geometrical rotations? 3. will your library provide a way to solve equation Ax=b (A is matrix, b and x are vectors, and x is the unknown). The background for question 2 above: Author of Boost.Quaternions tried to extend the library with code that would allow geomtetrical rotations, but at that time only Boost.Ublas library was available. After some investigation he discovered that matrices and vectors from ublas are unsuitable for the task, and finally he gave up. Following functions would be needed: operator*(vector<3,T1>,quaternion<T2>) // most important from_rotation_matrix(matrix<3,3,T>) to_rotation_matrix() from_axis_angle(vector<3,T1> axis, T2 angle) to_axis_angle() to_euler_angles() and few others. Similar functionality is already in boost vault: directory "Math - Numerics", file Quaternion.h Without quaternion rotations this linear algebra library would be pretty useless for me, so I hope it'll be there :) -- Janek Kozicki |

Janek Kozicki <janek_listy <at> wp.pl> writes:
Hello,
Not so long ago you have mentioned that you are working on a linear algebra library. I'm very interested in this topic, because I'm using such library in my project.
I have looked into the vault but couldn't find this library. Can we have a sneak peek?
Questions:
[SNIP]
2. will your library allow Boost.Quaternions to be extended in a way that those two libraries together will be useful for geometrical rotations?
[SNIP]
The background for question 2 above:
Author of Boost.Quaternions tried to extend the library with code that would allow geomtetrical rotations, but at that time only Boost.Ublas library was available. After some investigation he discovered that matrices and vectors from ublas are unsuitable for the task, and finally he gave up.
Following functions would be needed:
operator*(vector<3,T1>,quaternion<T2>) // most important from_rotation_matrix(matrix<3,3,T>) to_rotation_matrix() from_axis_angle(vector<3,T1> axis, T2 angle) to_axis_angle() to_euler_angles()
and few others. Similar functionality is already in boost vault: directory "Math - Numerics", file Quaternion.h
Without quaternion rotations this linear algebra library would be pretty useless for me, so I hope it'll be there :)
Paris (U.E.), le 13/07/2006 Bonjour If there is a reasonably standard (algebra, geometry) library to interface the quaternions with, I will provide the necessary functions. Speaking of the quaternion (and octonion) library, there are quite a few things which have been on my to-do list for quite some time now (like support for serialization) which I hope I will finaly have some time to work on this summer. Merci Hubert Holin

"Hubert Holin" wrote
Janek Kozicki <janek_listy <at> wp.pl> writes:
Following functions would be needed:
operator*(vector<3,T1>,quaternion<T2>) // most important from_rotation_matrix(matrix<3,3,T>) to_rotation_matrix() from_axis_angle(vector<3,T1> axis, T2 angle) to_axis_angle() to_euler_angles()
and few others. Similar functionality is already in boost vault: directory "Math - Numerics", file Quaternion.h
Without quaternion rotations this linear algebra library would be pretty useless for me, so I hope it'll be there :)
Paris (U.E.), le 13/07/2006
Bonjour
If there is a reasonably standard (algebra, geometry) library to interface the quaternions with, I will provide the necessary functions.
Speaking of the quaternion (and octonion) library, there are quite a few things which have been on my to-do list for quite some time now (like support for serialization) which I hope I will finaly have some time to work on this summer.
Is there any chance of writing some sort of quaternions for dummies documentation? Basically I am the dummy when it comes to maths , unless I have some job to perform like getting point x and rotating it about axis a through angle b. Unfortunately the higher level stuff is putting the quaternion library out of my reach. I think my only use for quaternions is for rotation. My basic use case (maybe like Janek) would be 1) some way to construct the quaternion from (say) an axis angle representation of the rotation 2) some way to apply it to a 3D point. I hope that I could then make use of the library without needing to know all the maths. BTW my plan is also to make a quaternion that is compatible with my Quan library: http://quan.sourceforge.net/index.html I did some test on complex quantities in a previous incarnation of Quan and there seemed to be no problems, so for instance one could do typedef complex<resistance> impedance; complex<voltage> v; complex<current> i impedance z = v / i; This is of course an entirely practical example. I guess that the same thing could be applied in 3D, though I don't know if there is such a practical use, though there may well be. Anyway these are the sorts of things I would like to try to do with a quaternion. regards Andy Little

On Fri, 14 Jul 2006 12:16:56 -0300, Andy Little <andy@servocomm.freeserve.co.uk> wrote:
Is there any chance of writing some sort of quaternions for dummies documentation? Basically I am the dummy when it comes to maths , unless I have some job to perform like getting point x and rotating it about axis a through angle b. Unfortunately the higher level stuff is putting the quaternion library out of my reach. I think my only use for quaternions is for rotation. My basic use case (maybe like Janek) would be
1) some way to construct the quaternion from (say) an axis angle representation of the rotation 2) some way to apply it to a 3D point.
Jaap Suter (http://jaapsuter.com/) has an introduction to geometric algebra in his home page. GA subsumes quaternions. He was also working in a C++ library that handled GA objects, including their units. Bruno

Andy Little <andy <at> servocomm.freeserve.co.uk> writes:
"Hubert Holin" wrote
Janek Kozicki <janek_listy <at> wp.pl> writes:
Paris (U.E.), le 17/07/2006 Bonjour
Following functions would be needed:
operator*(vector<3,T1>,quaternion<T2>) // most important from_rotation_matrix(matrix<3,3,T>) to_rotation_matrix() from_axis_angle(vector<3,T1> axis, T2 angle) to_axis_angle() to_euler_angles()
and few others. Similar functionality is already in boost vault: directory "Math - Numerics", file Quaternion.h
Without quaternion rotations this linear algebra library would be pretty useless for me, so I hope it'll be there :)
Paris (U.E.), le 13/07/2006
Bonjour
If there is a reasonably standard (algebra, geometry) library to interface the quaternions with, I will provide the necessary functions.
[SNIP]
Is there any chance of writing some sort of quaternions for dummies documentation? Basically I am the dummy when it comes to maths , unless I have some job to perform like getting point x and rotating it about axis a through angle b. Unfortunately the higher level stuff is putting the quaternion library out of my reach. I think my only use for quaternions is for rotation. My basic use case (maybe like Janek) would be
1) some way to construct the quaternion from (say) an axis angle representation of the rotation 2) some way to apply it to a 3D point.
I hope that I could then make use of the library without needing to know all the maths.
I am willing to build the bridges, but there has to bee something at the end of the bridge :-) ! There are geometry-oriented C++ libraries outside Boost, but none within, despite several proposals to develop such over the last few years. Basicaly, that's why I included some example code to show how quaternions could be plugged into rotation matrices, but no formal, part-of-the-library component. I would of course welcome the inclusion of geometry-oriented libraries within Boost (and I truly believe there is an actual need for them). I should add this is not a symptom of NIH, it is just that one has to learn a library to interface with it, and this does take time. There is no much point in spending that time for libraries whose future is at the whim of some brainless corporation, or depends upon only the long-term interest and availability of academia (as, sadly, these later usualy highly interesting libraries have a nasty habit of dying after a few years at most).
BTW my plan is also to make a quaternion that is compatible with my Quan library:
http://quan.sourceforge.net/index.html
I did some test on complex quantities in a previous incarnation of Quan and there seemed to be no problems, so for instance one could do
typedef complex<resistance> impedance; complex<voltage> v; complex<current> i
impedance z = v / i;
This is of course an entirely practical example.
In a similar vein, it would be fun to do simulations using the quaternionic version of Maxwell's equations.
I guess that the same thing could be applied in 3D, though I don't know if there is such a practical use, though there may well be.
My first reason to look at quaternions was to solve a 3D problem (interpolation of orientations under constraints). So yes, there is immense practical use in that field as well.
Anyway these are the sorts of things I would like to try to do with a quaternion.
regards Andy Little
Merci Hubert Holin

"Hubert Holin" <Hubert.Holin@lmd.polytechnique.fr> wrote
I am willing to build the bridges, but there has to bee something at the end of the bridge :-) ! There are geometry-oriented C++ libraries outside Boost, but none within, despite several proposals to develop such over the last few years. Basicaly, that's why I included some example code to show how quaternions could be plugged into rotation matrices, but no formal, part-of-the-library component.
I am happy to do the work. I hope that you might be willing to make sure that the output makes some sort of sense though :-) FWIW Here is a reinterpretation of the quaternion_to_R3_rotation in http://www.boost.org/libs/math/quaternion/HSO3.hpp reworked by Janek Kozicki and myself, (Any errors are my responsibility !) The matrices have been substituted with 3D vectors, some optimisation has been done and the code is compatible with the tentative Quan physical quantities Boost physical quantities library.as well as with floating point types. // Copyright Hubert Holin, Janek Kozicki, Andrew Little 2006 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // It might be better as a named function rather than an operator * template <typename TL, typename TR> inline quan::three_d::vect<TR> operator *( quan::three_d::quat<TL> const & lhs, quan::three_d::vect<TR> const & rhs //NB will become vect<3,TR> ) { TL const& a = lhs.w; TL const& b = lhs.x; TL const& c = lhs.y; TL const& d = lhs.z; // e.g typedef typeof(TL() * TR()) quat_squared_type; typedef typename quan::meta::binary_operation< TL, quan::meta::times, TL >::type quat_squared_type; quat_squared_type aa = a*a; quat_squared_type bb = b*b; quat_squared_type cc = c*c; quat_squared_type dd = d*d; quat_squared_type norme_carre = aa+bb+cc+dd; /* // throwing would be a good idea if nome-carre is too small! */ quat_squared_type ab = a*b; quat_squared_type ac = a*c; quat_squared_type ad = a*d; quat_squared_type bc = b*c; quat_squared_type bd = b*d; quat_squared_type cd = c*d; typedef quan::three_d::vect<quat_squared_type> squared_vect; squared_vect svx(aa+bb-cc-dd,2*(-ad+bc),2*(ac+bd)); squared_vect svy(2*(ad+bc),(aa-bb+cc-dd),2*(-ab+cd)); squared_vect svz(2*(-ac+bd),2*(ab+cd),(aa-bb-cc+dd)); quan::three_d::vect<TR> result( dot_product(svx,rhs)/norme_carre, dot_product(svy,rhs)/norme_carre, dot_product(svz,rhs)/norme_carre ); return result; } <...>
typedef complex<resistance> impedance; complex<voltage> v; complex<current> i
impedance z = v / i;
This is of course an entirely practical example.
In a similar vein, it would be fun to do simulations using the quaternionic version of Maxwell's equations.
That sounds like it would provide some good examples for the Quan library! http://sourceforge.net/projects/quan regards Andy little

Andy Little <andy <at> servocomm.freeserve.co.uk> writes:
"Hubert Holin" <Hubert.Holin <at> lmd.polytechnique.fr> wrote
I am willing to build the bridges, but there has to bee something at the end of the bridge ! There are geometry-oriented C++ libraries outside Boost, but none within, despite several proposals to develop such over the last few years. Basicaly, that's why I included some example code to show how quaternions could be plugged into rotation matrices, but no formal, part-of-the-library component.
I am happy to do the work. I hope that you might be willing to make sure that the output makes some sort of sense though
Yes, certainly (there is a chance, this time, that I will actually have the time to work on many of the things I promissed long ago).
FWIW Here is a reinterpretation of the quaternion_to_R3_rotation in http://www.boost.org/libs/math/quaternion/HSO3.hpp
OK, I'll take a look in a couple of days (I am just back from vacation, and currently frenetically playing "cat soup" ;-) ). Merci Hubert Holin

"Andy Little" <andy@servocomm.freeserve.co.uk> writes:
BTW my plan is also to make a quaternion that is compatible with my Quan library:
http://quan.sourceforge.net/index.html
I did some test on complex quantities in a previous incarnation of Quan and there seemed to be no problems, so for instance one could do
typedef complex<resistance> impedance; complex<voltage> v; complex<current> i
impedance z = v / i;
This is of course an entirely practical example.
Without knowing the details of your library, a well-designed generic library usually defines non-intrusive concepts that allow any type to satisfy the requirements, given some additional traits and functions. There should be no need to write a new quaternion. -- Dave Abrahams Boost Consulting www.boost-consulting.com

David Abrahams said: (by the date of Wed, 30 Aug 2006 15:26:43 -0400)
Without knowing the details of your library, a well-designed generic library usually defines non-intrusive concepts that allow any type to satisfy the requirements, given some additional traits and functions. There should be no need to write a new quaternion.
with the context of physical units I would like to point to you following example: A function somewhere in the MTL4 library, with following signature: vector<3,T> operator*(vector<3,T> lhs, T rhs) // multiply vector by scalar { return vector<3,T>(lhs.x*rhs, lhs.y*rhs, lhs.z*rhs); } // now the testing code #include <boost/units.hpp> #include <boost/liear_agebra.hpp> int main() { // disclaimer: of course implementation details of unit and // linear_algebra libraries are unknown, for the sake of this example I // had to make some assumptions when writing it. vector<3,boost::unit::length::m> v(10,20,30); // unit [meter] boost::unit::length::m k(3); // unit [meter] typedef length_squared boost::unit::squared<boost::unit::length::m>::value_type; // unit [meter^2] vector<3,length_squared> result=v*k; // error !! } As you can see the return type in this case is different than the type of arguments supplied. Because from type T we get to type T*T (meter squared). The impact of this "error" is huge. It means that return types of all functions in MTL4 library are not straightforward - they must be appropiately calculated by the compiler. In above example the return type is a result of multiplicating two types. Does MTL4 already take care of that? -- Janek Kozicki |

"David Abrahams" <dave@boost-consulting.com> wrote in message news:87d5aim3d8.fsf@pereiro.peloton...
typedef complex<resistance> impedance; complex<voltage> v; complex<current> i
impedance z = v / i;
This is of course an entirely practical example.
Without knowing the details of your library, a well-designed generic library usually defines non-intrusive concepts that allow any type to satisfy the requirements, given some additional traits and functions. There should be no need to write a new quaternion.
Without knowing the details of Your library....etcetera... One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan. Of course whether it has a practical use is another matter :-) regards Andy Little

Andy Little wrote:
One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan.
This is a worthy goal. As a biased modern differential geometer, my view is that this would be a lot easier if you were to write Maxwell's equations with respect to the Minkowski space-time metric and using differential forms. A lot of stuff fits together in a more logical consistent fashion when you do this.
Of course whether it has a practical use is another matter :-)
Yeah, but who cares? I like the spirit. But this is probably waaaaay off topic for this newsgroup.

"Deane Yang" <deane_yang@yahoo.com> wrote in message news:ed5ero$sbm$1@sea.gmane.org...
Andy Little wrote:
One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan.
This is a worthy goal. As a biased modern differential geometer, my view is that this would be a lot easier if you were to write Maxwell's equations with respect to the Minkowski space-time metric and using differential forms. A lot of stuff fits together in a more logical consistent fashion when you do this.
Well the real goal is to *somehow* model electric and magnetic fields, and similarly for aerodynamics in 3D space, or at least to make some very simple approximations to the reality. Though actually FWIW I'll probably limit my horizons to just a quan::complex for the moment :-)
Of course whether it has a practical use is another matter :-)
Yeah, but who cares? I like the spirit.
But this is probably waaaaay off topic for this newsgroup.
Not IMO. linear algebra isnt much use without some applications. regards Andy Little

On Aug 31, 2006, at 10:50 AM, Andy Little wrote:
"Deane Yang" <deane_yang@yahoo.com> wrote in message news:ed5ero$sbm$1@sea.gmane.org...
Andy Little wrote:
One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan.
This is a worthy goal. As a biased modern differential geometer, my view is that this would be a lot easier if you were to write Maxwell's equations with respect to the Minkowski space-time metric and using differential forms. A lot of stuff fits together in a more logical consistent fashion when you do this.
Well the real goal is to *somehow* model electric and magnetic fields, and similarly for aerodynamics in 3D space, or at least to make some very simple approximations to the reality. Though actually FWIW I'll probably limit my horizons to just a quan::complex for the moment :-)
Can't you just use std::complex<T> as value type in quan?

"Matthias Troyer" <troyer@itp.phys.ethz.ch> wrote in message news:3BF6C3DF-9F29-4CCE-BF04-D97B8CADFE83@itp.phys.ethz.ch...
Can't you just use std::complex<T> as value type in quan?
You can do: quan::resistance<std::complex<> >:kR x; but its preferable to do: quan::complex<quan::resistance::kR> x; I tried specialising/ overloading std::complex for quantities before but its more work than just doing my own version, which will work with numeric types and quantity types anyway.... and complex<double>(1) * 2; won't fail to compile in my version ;-) regards Andy Little

Andy Little wrote:
I tried specialising/ overloading std::complex for quantities before [...]
Is this legal? Standard says (section 26.2, verse 2): ``The effect of instantiating the template complex for any type other than float, double or long double is unspecified.'' Regards, fres

"Andy Little" <andy@servocomm.freeserve.co.uk> writes:
"David Abrahams" <dave@boost-consulting.com> wrote in message news:87d5aim3d8.fsf@pereiro.peloton...
typedef complex<resistance> impedance; complex<voltage> v; complex<current> i
impedance z = v / i;
This is of course an entirely practical example.
Without knowing the details of your library, a well-designed generic library usually defines non-intrusive concepts that allow any type to satisfy the requirements, given some additional traits and functions. There should be no need to write a new quaternion.
Without knowing the details of Your library....etcetera...
Huh?
One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan.
What does that have to do with what I posted? -- Dave Abrahams Boost Consulting www.boost-consulting.com

"David Abrahams" <dave@boost-consulting.com> wrote in message news:uzmdlq6j8.fsf@boost-consulting.com...
"Andy Little" <andy@servocomm.freeserve.co.uk> writes:
"David Abrahams" <dave@boost-consulting.com> wrote in message news:87d5aim3d8.fsf@pereiro.peloton...
typedef complex<resistance> impedance; complex<voltage> v; complex<current> i
impedance z = v / i;
This is of course an entirely practical example.
Without knowing the details of your library, a well-designed generic library usually defines non-intrusive concepts that allow any type to satisfy the requirements, given some additional traits and functions. There should be no need to write a new quaternion.
Without knowing the details of Your library....etcetera...
Huh?
Sorry, I can't remember what I was driving at there either.
One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan.
What does that have to do with what I posted?
Nothing I guess.

Andy Little wrote:
"David Abrahams" <dave@boost-consulting.com> wrote in message
Huh?
Sorry, I can't remember what I was driving at there either.
One way or another, presenting Maxwells Equations in the form of physical quantities is a goal of Quan. What does that have to do with what I posted?
Nothing I guess.
I also apologize for my equally irrelevant response to Andy.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello I just started reading some of the messages about physical Unit. I have been wrestling with these for some time. Here are some conclusions/decision I have taken: 1. Use the units classes mainly for I/O. 2. Convert all quantities to SI. 3. On Input give the user a clue as to what units are available. Find attached the files with my classes for handling unit. Thanks J N Hinckel Andy Little wrote: -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFE9z7xTuQ+wJa/AYQRAnSAAJ4hjBxoC4wRYRKjlWD8Yw/5KWr6QQCgla80 4BcjPriGcj6p2txGEgVDGRc= =hGxQ -----END PGP SIGNATURE-----

Janek Kozicki <janek_listy@wp.pl> writes:
Hello,
Not so long ago you have mentioned that you are working on a linear algebra library. I'm very interested in this topic, because I'm using such library in my project.
I'm sorry I've been so quiet...
I have looked into the vault but couldn't find this library. Can we have a sneak peek?
I'm sorry, not yet. We have lots of code, but nothing worth showing at the linear algebra level.
Questions:
1. will your library provide functions useful when working with small vectors like: cross_product(), dot_product(), normalize() (scale vector so its length()==1), norm() (returns squared length), length(), etc... ?
Yes, and it will minimize the amount of temporary storage used, so it should be very fast.
2. will your library allow Boost.Quaternions to be extended in a way that those two libraries together will be useful for geometrical rotations?
Probably. Well-designed generic libraries usually use concepts that are not dependent on member functions, so it should be possible to write the traits and other components that make that work.
3. will your library provide a way to solve equation Ax=b (A is matrix, b and x are vectors, and x is the unknown).
Yes.
The background for question 2 above:
Author of Boost.Quaternions tried to extend the library with code that would allow geomtetrical rotations, but at that time only Boost.Ublas library was available. After some investigation he discovered that matrices and vectors from ublas are unsuitable for the task, and finally he gave up.
Following functions would be needed:
operator*(vector<3,T1>,quaternion<T2>) // most important
Is that an inner product, outer product, or pointwise multiplication?
from_rotation_matrix(matrix<3,3,T>)
returning what?
to_rotation_matrix()
Where's the argument? Is this supposed to be a member function? See my 4th paragraph above.
from_axis_angle(vector<3,T1> axis, T2 angle)
returning what?
to_axis_angle()
Where's the argument?
to_euler_angles()
Where's the argument?
and few others. Similar functionality is already in boost vault: directory "Math - Numerics", file Quaternion.h
Without quaternion rotations this linear algebra library would be pretty useless for me, so I hope it'll be there :)
OK. -- Dave Abrahams Boost Consulting www.boost-consulting.com

David Abrahams said: (by the date of Wed, 30 Aug 2006 15:20:33 -0400)
Janek Kozicki <janek_listy@wp.pl> writes:
Hello,
Not so long ago you have mentioned that you are working on a linear algebra library. I'm very interested in this topic, because I'm using such library in my project.
I'm sorry I've been so quiet...
Hello, much better late than never :)) Many thanks for your answer.
I have looked into the vault but couldn't find this library. Can we have a sneak peek?
I'm sorry, not yet. We have lots of code, but nothing worth showing at the linear algebra level.
ok. I have found that it is MTL4, mentioned here: http://osl.iu.edu/research/mtl/
Questions: 1. will your library provide cross_product(), etc... ?
Yes, and it will minimize the amount of temporary storage used, so it should be very fast.
great! :)
2. will your library allow Boost.Quaternions to be extended in a way that those two libraries together will be useful for geometrical rotations?
Probably. Well-designed generic libraries usually use concepts that are not dependent on member functions, so it should be possible to write the traits and other components that make that work.
then I hope that upon adding MTL4 to boost such functions (described below in more detail) will be added too.
3. will your library provide a way to solve equation Ax=b ?
Yes.
great again :)
The background for question 2 above: Following functions would be needed:
operator*(vector<3,T1>,quaternion<T2>) // most important
Is that an inner product, outer product, or pointwise multiplication?
None of above. This function operator* performs a rotation of three element vector by quaternion. It is possible that you will prefer a function name "rotate" instead of "operator* ". (Although operator* is very convenient for people who work with quaternions). The rotation is done by first building a rotation matrix from quaternion, and then multiplying vector by this matrix. See: http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation Scroll down this webpage to the bottom, in the section titled "Quaternions versus other representations of rotations" you can see that matrix mentioned above. The code to do that may look like this: vector<3,T> operator* (const quaternion<T>& lhs,const vector<3,T>& rhs) { T aa = lhs.w*lhs.w; T ab = lhs.w*lhs.x; T ac = lhs.w*lhs.y; T ad = lhs.w*lhs.z; T bb = lhs.x*lhs.x; T bc = lhs.x*lhs.y; T bd = lhs.x*lhs.z; T cc = lhs.y*lhs.y; T cd = lhs.y*lhs.z; T dd = lhs.z*lhs.z; T mag = aa+bb+cc+dd; // [1] // build matrix elements (possibly building an MTL4::matrix<3,3,T> will be a better coding here?) T at11 = (aa+bb-cc-dd)/mag; T at12 = 2*(-ad+bc)/mag; T at13 = 2*(ac+bd)/mag; T at21 = 2*(ad+bc)/mag; T at22 = (aa-bb+cc-dd)/mag; T at23 = 2*(-ab+cd)/mag; T at31 = 2*(-ac+bd)/mag; T at32 = 2*(ab+cd)/mag; T at33 = (aa-bb-cc+dd)/mag; // returns rotated vector return vector<3,T> ( rhs.x*at11 + rhs.y*at12 + rhs.z*at13 ,rhs.x*at21 + rhs.y*at22 + rhs.z*at23 ,rhs.x*at31 + rhs.y*at32 + rhs.z*at33 ); } [1] this is only to ensure that quaternion has magnitude==1, in that wikipedia article this denominator is not mentioned, because it is assumed that quaternion already has magnitude==1. This assumption could also be made in this function, and then variable 'mag' could be removed. And when this function will be called with quaternion of magnitude!=1, then results will be invalid.
from_rotation_matrix(matrix<3,3,T>)
returning what?
I'm sorry for being not specific. This function is supopsed to create a quaternion when given a matrix<3,3,T>. This matrix is supposed to be a rotation matrix. Function signature: quaternion<T> from_rotation_matrix(matrix<3,3,T>); sample implementation starts from line 382 in file Quaternion.h from boost vault: http://www.boost-consulting.com/vault/index.php?directory=Math%20-%20Numeric... Although I don't know why the argument to this function is a 4x4 matrix in this concrete implementation. Perhaps I should investigate more.
to_rotation_matrix()
Where's the argument? Is this supposed to be a member function? See my 4th paragraph above.
Not necessarily a member function, if not then the function signature would look like: matrix<3,3,T> to_rotation_matrix(quaternion<T>); This function is supposed to create a rotation matrix when given a quaternion. Sample implementation is above in this email (part of rotation operator* code), or starting from line 327 from Quaternion.h in boost vault (please note that there the returned matrix is 4x4 but its last row and column are neutral => unnecessary).
from_axis_angle(vector<3,T1> axis, T2 angle)
returning what?
Function signature: quaternion<T> from_axis_angle(vector<3,T> axis, T angle); This function is suposed to create a quaternion when given an axis of rotation and angle of rotation around this axis, sample implementation may look like: quaternion<T> from_axis_angle(vector<3,T> axis, T angle) { T half_angle = angle*0.5; vector<3,T> sin_axis = sin(half_angle)*axis; return quaternion<T>( cos(half_angle) ,sin_axis.x ,sin_axis.y ,sin_axis.z); } Or look at line 305 of file Quaternion.h from boost vault.
to_axis_angle()
Where's the argument?
This function does the opposite, returns axis and angle when given a quaternion. Function signature: void to_axis_angle(vector<3,T>& axis, T& angle, quaternion<T>); or alternatively, without taking references to existing variables: std::pair<vector<3,T>,T> to_axis_angle(quaternion<T>); This function is mathematically opposite of from_axis_angle, and involves arcus cosinus :)
to_euler_angles()
Where's the argument?
This function takes as argument a quaternion and converts it into euler angle representation of rotation. Function signature: vector<3,T> to_euler_angles(quaternion<T>); Function implementation, for example from: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
and few others. Similar functionality is already in boost vault: directory "Math - Numerics", file Quaternion.h
just a reminder: http://www.boost-consulting.com/vault/index.php?directory=Math%20-%20Numeric...
Without quaternion rotations this linear algebra library would be pretty useless for me, so I hope it'll be there :)
OK.
I hope that it is more clear now :) I'll be glad to explain more if necessary (and help with coding too, according to my abilities ;). -- Janek Kozicki |
participants (9)
-
Andy Little
-
Bruno Martínez
-
David Abrahams
-
Deane Yang
-
Hubert Holin
-
Janek Kozicki
-
Jose N Hinckel
-
KF
-
Matthias Troyer