0

I'm trying to figure out what is going on here:

having a System.Drawing.Drawing2D.Graphics objects called g.

g.Transform has these values:

[0] = 1
[1] = 0
[2] = 0
[3] = -1
[4] = 0
[5] = 1122.66663

when doing

int minAngle = 0;
g.Transform.Rotate(360 - minAngle);

I get the same elements for the g.Transform property:

[0] = 1
[1] = 0
[2] = 0
[3] = -1
[4] = 0
[5] = 1122.66663

However when I do:

int minAngle = 0;
g.RotateTransform(360 - minAngle);

I get these elements for the g.Transform property:

[0] = 0.99999994
[1] = 3.019916E-07
[2] = 3.019916E-07
[3] = -0.99999994
[4] = 0
[5] = 1122.66663

Why is there such a big rounding difference between both methods, which seem to do the same: modifying the world transform?

Besides the floating point rounding 'issue', is there any difference when using rotateTransfrom vs. transform.rotate ?

(.NET Framework 4.8)

juFo
  • 17,849
  • 10
  • 105
  • 142
  • it doesn't explain why both functions behave differently as they do 'the same'...? I know floating point has rounding 'issues' but doesn't explain the difference in both methods. – juFo Jun 08 '21 at 09:24
  • How are those differences 'big'? – TaW Jun 08 '21 at 09:29
  • big enough to result in a 'Parameter is not valid' when assigning the RotateTransform to a matrix. (doesn't happen with g.Transform.Rotate). So actually breaks existing working code it seems... – juFo Jun 08 '21 at 10:44
  • Can you show the code? Most likely it is not too big but too small for some geometric operations. So, yes, you may have to insert checks/corrections.. – TaW Jun 08 '21 at 11:24
  • I've showed 'the code'. just a graphics object where transform property has the values as said in the post. next just a simple rotatetransform vs. transform.rotate giving different rounding results. – juFo Jun 08 '21 at 12:28
  • I meant the code that results to the 'Parameter is not valid' error. – TaW Jun 08 '21 at 14:19
  • turns out that code was a small miscalculation resulting in an incorrect transformation. You can ignore that :-) (back again to the differences on why one calculates "correctly" and the other "doesn't") – juFo Jun 08 '21 at 14:41
  • _back again to the differences on why one calculates "correctly" and the other "doesn't"_ The quote characters are the answer: In the realm of floating point numbers the perceived difference is moot. – TaW Jun 08 '21 at 15:04

0 Answers0