[cairo] Rotations with Quaternions
bryce at osg.samsung.com
Wed Jan 10 00:40:38 UTC 2018
On Mon, Jan 08, 2018 at 01:43:50PM -0500, cecashon at aol.com 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.
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
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?
> cairo mailing list
> cairo at cairographics.org
More information about the cairo