Groups | Blog | Home
all groups > dotnet drawing api > september 2005 >

dotnet drawing api : matrix problem


SharpCoderMP
9/5/2005 2:52:56 PM
hi,
i'm not too good at math, can anyone help me with this?
i do some transformations to the point:

Matrix mx = new Matrix();
mx.Scale(_scale,_scale);
mx.Invert();
Point[] pts = new Point[] { p }; // where *p* is my point to transform.
mx.TransformPoints(pts);

now i would like to make reversed transformation, to go back to the origin.
i thought that mx.Scale((1/_scale),(1/_scale)); wolud do what i need but
Andrew Kirillov
9/5/2005 4:41:34 PM
Hello.

Here is the code, which makes tranform and back transform. But, be careful
using the same with Point instead of PointF. In the case of Point it will no
be always possible to transform back, because you are loosing part of
information.

PointF p = new Point(4, 4);
Matrix mx = new Matrix();
mx.Scale(3, 3);
mx.Invert();

PointF[] pts = new PointF[] { p };
mx.TransformPoints(pts);

System.Diagnostics.Debug.WriteLine("x = " + pts[0].X + ", y = " + pts[0].Y);

mx.Invert();
mx.TransformPoints(pts);

System.Diagnostics.Debug.WriteLine("x = " + pts[0].X + ", y = " + pts[0].Y);


--
With best regards,
Andrew

http://www.codeproject.com/script/profile/whos_who.asp?id=1181072


[quoted text, click to view]

SharpCoderMP
9/5/2005 4:43:46 PM
thanks,

to make things clear:
if i'd like to transform back with new matrix, then i should do this:
PointF p = new Point(4, 4);
Matrix mx = new Matrix();
mx.Scale(3, 3);
mx.Invert();

PointF[] pts = new PointF[] { p };
mx.TransformPoints(pts);

Matrix mx2 = new Matrix();
mx2.Scale(3, 3);
mx2.TransformPoints(pts);

now (in theory) my pts[0] should be 4,4
in fact it is as i tested this.
but i don't get this. i thought that when i do something like this:
Matrix mx = new Matrix();
mx.Scale(3,3);
mx.Invert();
mx.TransformPoints(pts);

Matrix mx2 = new Matrix();
mx2.Invert();
mx2.Scale(1.0/3,1.0/3);
mx2.TransformPoints(pts);

then i'll get the same results. but i dont.



[quoted text, click to view]
AddThis Social Bookmark Button