Boost logo

Boost :

Subject: Re: [boost] [geometry] few questions
From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2010-04-23 09:36:49


Emil Dotchevski said: (by the date of Fri, 23 Apr 2010 00:55:33 -0700)

> On Fri, Apr 23, 2010 at 12:19 AM, Barend Gehrels <barend_at_[hidden]> wrote:
> > http://www.revergestudios.com/boost-la/
> > If accepted, we plan to merge vector operations / let them interoperate
> > between geometries.
>
> For Janek's sake, you just define a simple traits type for any vector
> type, and the generic vector operations in (Boost) LA kick-in
> automatically.
>
> >> Last but not least - I am doing frequently a 3D rotation of 3D points
> >> using quaternions for that (this could work with rotation matrices
> >> too). I suppose that I would need to implement this myself to "link"
> >> boost::quaternion with boost::geometry::point3d.
>
> I've also implemented generic quaternion operations in (Boost) LA that
> kick-in for user-defined types, but I haven't yet published that code
> because I haven't got a chance to update the documentation. Hopefully
> soon.

Many thanks for your answers. Currently I have boost 1.42 installed.
I can download your libraries and put them in include/ directory (are
those include only?). So I can use them. But can they work for me?

To answer this, could you tell me how such a "very simple" program
using your libraries could look? Full source is in the attachment.
(I am using currently some parts of WildMagic 3 library,which is under
LGPL license).

Here's the simple program (full version in attachment):

#include <iostream>
#include <string.h>
#include "Vector3.hpp"
#include "Quaternion.hpp"

using namespace std;

int main()
{
        Vector3d a,b,c; // declare some 3D vectors
        a = Vector3d( 0.0 , 0.0 , 1.0 ); // initialize them somehow
        b = Vector3d( 0.0 , 0.0 , -1.0 );
        c = Vector3d( 0.0 , 2.0 , 0.0 );
        cout << "\ndeclared 3D vectors:\n";
        cout << "a: " << a << "\n";
        cout << "b: " << b << "\n";
        cout << "c: " << c << "\n";
        
        cout << "a + c: " << a+c << endl; // vector addition test
        cout << "a x c: " << a.cross(c) << endl; // vector cross product test
        cout << "a . b: " << a.dot(b) << endl; // vector dot product test

        Quaterniond q; // declare some quaternion

        q.align(b,a); // now quaternion q will describe a rotation from vector a to vector b
        cout << "\nquaternion q (which rotates vector a into vector b): " << q << endl;

        Vector3d axis;
        double angle;
        q.toAxisAngle(axis,angle); // now, represent this rotation q as an axis-angle pair
        cout << "axis of rotation: " << axis << " angle of rotation: " << angle << endl;

        cout << "So now, let's rotate a by quaternion q, did we get b from that?\n";
        cout << "q*a: " << q*a << endl;
        cout << "b: " << b << endl;
};

// program output:
//
// declared 3D vectors:
// a: 0 0 1
// b: 0 0 -1
// c: 0 2 0
// a + c: 0 2 1
// a x c: -2 0 0
// a . b: -1
//
// quaternion q (which rotates vector a into vector b): 0 0 -1 0
// axis of rotation: 0 -1 0 angle of rotation: 3.14159
// So now, let's rotate a by quaternion q, did we get b from that?
// q*a: 0 0 -1
// b: 0 0 -1

Once I have figured out how to do above code using boost + your
libraries only, I will be very happy to switch to boost entirely.
Also - I will be very happy to test your library and submit bug
reports or patches, but let's get this simple example to work first.

Composing rotations by multiplying quaternions should work too. And
normalizing them, conjugating, inverting, etc, but all that is
already in boost::quaternion.

best regards

-- 
Janek Kozicki                               http://janek.kozicki.pl/  |



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk