GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
Go Back  Xtreme Visual Basic Talk > > > GdipSetMatrixElements vs GdipTranslateMatrix


Reply
 
Thread Tools Display Modes
  #1  
Old 06-14-2017, 10:09 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default GdipSetMatrixElements vs GdipTranslateMatrix


Quite by accident I found the following 2 lines perform the exact same thing... they move the graphics path object 350 pixels to the right.

Code:
'stat = GdipSetMatrixElements(mtrx, 1, 0, 0, 1, 350, 0)
'or
stat = GdipTranslateMatrix(mtrx, 350, 0, MatrixOrderAppend)

stat = GdipTransformPath(path, mtrx)
Could someone please explain the GdipSetMatrixElements function... especially the 1, 0, 0, 1 parameters?
Reply With Quote
  #2  
Old 07-10-2017, 02:46 PM
passel's Avatar
passelGdipSetMatrixElements vs GdipTranslateMatrix passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

You can try to read the remarks here to see if you can make any sense of how the matrix works.
There are a number of convenience methods, e.g. GdipTranslateMatrix, that will change he appropriate matrix elements so you don't have to remember which of the raw elements that would have to be changed to implement rotation, scaling and transforming.

One way that I tend to look at the matrix when I do consider the raw values (more common when I'm dealing with a color matrix), is that at least for the four values you indicated that X,Y values are coming into the matrix from the left (X being input to the top row, and Y being input to the second row) and the output X and Y values are coming out the top (X from the first column and Y from the second column).
The value coming in fom the left are multiplied by the value in the intersection cell and then go out the top.
Code:
      ^   ^
      X   Y
    ---------
X > | 1 | 0 |
    |---|---|
Y > | 0 | 1 |
    ----------
The above portion of the matrix is what you're referring to (1,0, 0,1) and is known as the identity matrix because the value of X comes in, is multiplied by 1 and goes out unchanged. Likewise the value of Y comes in , is multiplied by 1 and goes out unchanged. The input value of X has no influence on the output of Y (the value 0 at that intersection gives us 0 * X = 0), likewise the value of Y has no influence on the value of X.
If you changed the Xin,Xout intersection to a number other than 1 then you are scaling the value of X, example (2,0,0,1) would double the X value out. Of course you could use the ScaleTransform method to change first and fourth values of the matrix elements to do scaling.

Now rotation is a bit more complicated, but the basic principle still applies. In order to rotate, the X input value will be multiplied by some value to influence the Y output, likewise, the Y input value will be multiplied by some value to influence the X output.
The X and Y ratio values are related to rotation angle and we know these ratios by the names Sine and Cosine values.

I won't go into the details, but when you use the RotateTransform method you should see that the two 0,0 values in the Xin,Yout cell and the Yin,Xout cell intersections have different values that will take the X input value and scale it by the factor and output it from the Y output column. Likewise, the Y input value will be scaled by the appropriate value in the Yin,Xout intersection cell to output an X value. This scaling of Xin to Yout and Yin to Xout, if the values are appropriate, will result in a rotation. If the values are not appropriate for rotation (i.e. not the correct ratios based on an angle), then you'll get a skewing effect.

Hopefully, that visualization of X and Y inputs affecting X and Y outputs based on the values at the intersection of the Input (rows) and output (columns) helps to understand the basic principle. You can read up on matrix math to get a more detailed description of how the values are actually mathematically multiplied and added to get the results, but the fairly simple (I think) idea of inputs coming in from the left, multiplied by the intersection value and going out the top for the respective X,Y value makes the concept a little easier for me to comprehend what is going on, basically.

The third row (the translate row) works a bit differently, in that the value in the column is simply added to the output of that column, so per your example, you are just adding 350 to the X value.

I've ignored how the values are combined when you have both X and Y inputs affecting one of the outputs (e.g. when you have Xin multiplied by Xin,Xout cell intersection and Yin multiplied by the Yin/Xout cell intersection so both Xin and Yin are affecting Xout.
I would have to look that up to be sure, and don't really have the interest in any case. I usually count on using the existing methods to modify the matrix for scaling, rotating and translating, so don't have a need to operate on the elements of the matrix directly.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 07-10-2017 at 02:54 PM.
Reply With Quote
  #3  
Old 07-16-2017, 09:54 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

Wow... complicated stuff
I will try to wrap my head around your reply

From my first read, it appears you can do all graphics transformations using the GdipSetMatrixElements call (ie setting each of the six input values)
rather than the GdipTranslateMatrix, GdipScaleMatrix, GdipRotateMatrix

Is there an advantage to this call (speed maybe?)
Reply With Quote
  #4  
Old 07-17-2017, 01:56 PM
passel's Avatar
passelGdipSetMatrixElements vs GdipTranslateMatrix passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I don't know offhand, and won't bother trying to test it. Functionally, since the needed code should be the same whether you do it or the method does it, I think the speed should be very much the same.
In particular, if you wanted to do a rotation, you would have to take the angle (in Radians), calculate sine and cosine values yourself and then assign them to the proper parameters in the GdipSetMatrixElements call.
It is much easier to just pass the Angle in degrees to the GdipRotateMatrix method and have it do the work.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
gdipsetmatrixelements, gdipsetmatrixelementsmtrx, gdiptranslatematrixmtrx, stat, gdiptranslatematrix


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
 
GdipSetMatrixElements vs GdipTranslateMatrix
GdipSetMatrixElements vs GdipTranslateMatrix
 
-->