Re: Rotations with Quaternions

Bryce Harrington <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On Mon, Jan 08, 2018 at 01:43:50PM -0500, [email protected] wrote:
> 
> Hi Cairo Folks,
> 
> Would using quaternions for rotation and shear be workable internally
> in Cairo?
>
> It would make for a simplified function for setting up the rotation
> and shear of a drawing by requiring pitch, roll and yaw
> parameters. This is something that is visually easier for a programmer
> to understand even when drawing in 2d.

Internally Cairo uses matrices to handle transformations, and the
rotation and translation APIs are merely convenience routines on top of
the matrix math.  You could add other convenience routines on top to
provide programmers different mechanisms for applying transformations
relatively easily, so long as the operations can be rendered into matrix
operations internally to Cairo.


> This is some test code using quaternions with Cairo and GTK. 
> 
> https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/ellipse3.c
> 
> Eric

This code is doing all the transformation math user-side, calculating
all the coordinates, and then drawing the lines with cairo directly.  It
doesn't use Cairo's matrix transformation support at all.

Part of the trouble is that Cairo's transformation code only uses a
6-element (2x3) matrix.  For doing quaternions "properly" you would want
16-element (4x4) matrices, although I wonder if since the end result is
going to be a 2D representation if an 8- 9- element matrix would be
sufficient.

I've got some code I'm working on to expand Cairo's api to handle
projective transformation.  This will add px and py, thus allowing
8-element matrix transformations.  If you would be interested in doing
the code to provide a quaternion-based user API that represents the
changes as 8-element style matrix operations, perhaps you could build
that as a wrapper around the stuff I'm doing?

Bryce

> -- 
> cairo mailing list
> [email protected]
> https://lists.cairographics.org/mailman/listinfo/cairo

-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.