views:

330

answers:

3

I've used the Matrix class a thousand times. I have an elementary grasp of matrix mathematics, it's been years since I've had a class on the subject. But I don't fully understand what this class is doing under the hood to manipulate the points in a GraphicsPath.

What, specifically, is it doing in there as it pertains to GraphicsPaths in particular? Or another way to look at it, if the Matrix class didn't exist, and I had to create my own, what would it look like and what would it do? (I'm not creating my own I just want to understand it)

Furthermore, does anyone know the dimensions of the matrix used in the Matrix class?

EDIT: I've narrowed it down to the following call in reflector. From there, I've got bub kiss.

[DllImport("gdiplus.dll", CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
internal static extern int GdipTransformPath(HandleRef path, HandleRef matrix);
A: 

A GraphicsPath is, basically, a collection of points and a flags that explain how the points relate to one another. The matrix class simply applies the matrix to those points.

You could implement the same thing: 1. Create a new, empty GraphicsPath 2. Using a GraphicsPathIterator, iterate the paths (and subpaths) 3. Take each point and apply the matrix 4. Add that point to the new, GraphicsPath

But don't do it. The types in GraphicsPath are not well documented.

consultutah
+1  A: 

In this case, the Matrix class is a 2D transformation matrix. The Matrix is used to scale, rotate and / or translate the graphics path. The math is relatively straight forward. You can look at it here: http://en.wikipedia.org/wiki/Transformation_matrix

Scott P
So what are the dimensions of the Matrix? What do you think it's doing, multiplication? Man, I'm going to have to bone up on my linear geometry again.
blesh
While tjoho's article below is really interesting, and I strongly recommend anyone that comes here looking for answers to go look at it; I think this answer had more of the basics of what I was looking for. Thanks.
blesh
+1  A: 

One important thing to note if you are creating your own matrix class that is converting back and forth to the System.Drawing.Matrix class, is that the .NET one does not use the most commonly used standard when transforming points.

The .NET Matrix seems to be transposed before the transformation is taking place.

Also read the background here: http://www.codeproject.com/KB/recipes/psdotnetmatrix.aspx

I don't think I'll be creating my own, I just wanted a better understanding of what the heck was going on inside there so I can be sure that I'm making my code as efficient as possible.
blesh
Oh, that's a really cool project you linked btw, I'm looking forward to digging into it to see how it works.
blesh