[Kstars-devel] Testing the use of quaternions in KStars

Luciano Montanaro mikelima at cirulla.net
Mon Oct 2 15:10:18 CEST 2006


On Monday 02 October 2006 05:02, Jason Harris wrote:

> All that remains is to modify SkyMap::toScreen() to use the Quaternions
> in SkyPoint and SkyMap.  This is where I expected a significant
> improvement in CPU usage.  I created toScreenQuaternion(), which is
> really simple:
>
> QPointF SkyMap::toScreenQuaternion( SkyPoint *o, double scale ) {
> 	QPointF p;
> 	Quaternion oq = o->quat();
> 	oq.rotateAroundAxis( m_rotAxis );
>
> 	p.setX( 0.5*width()  - scale*oq.v[Q_X] );
> 	p.setY( 0.5*height() - scale*oq.v[Q_Y] );
>
> 	return p;
> }
>
I
> To test it, I added some timing code to time how long it takes to process
> 126,000 stars through toScreen(), and through toScreenQuaternion().  The
> results:
>
> toScreen():  22 ms
> toScreenQuaternion():  31 ms
>

I'm not familiar with quaternions per se. I guess they are quite similar to 
how homogeneous coordinates are used in 3D.

(basically, you can represent a point (x,y,z) in the cartesian space as 
(x,y,z,1) in the homogeneous space, and represent an infinitely distant 
point in the (x,y,z) direction as (x,y,z,0)).

I have written some more thought in the other answer, however here is the 
problem I see with this:

You should not do this kind of conversion one point at a time. the function 
call overhead will kill anything you may win by using simpler arithmetic.

Try to fill a Quaternion vector with the star coordinates first, and looping 
on that.
What does rotateAroundAxis() do? 
Actually, you just have to setup the 4x4 transformation matrix once to setup 
the rotation, then you just have to multiply the vector and the matrix. If 
this is what the function does, you want it to be inline.


Luciano


-- 
./.. ../ /./. .. ./ /. ///   // /// /. / ./ /. ./ ./. /// ././. //
                                                            \\ //
                                             www.cirulla.net \x/


More information about the Kstars-devel mailing list