transformation matrix; graphics

T

Thomas Bauer

Hello,

how can I make the transformation matrix?

Zero point
Left top
Left bottom
Right top
Right bottom

I have a list of points
private void Form1_Load(object sender, EventArgs e)
{
ListCodes = new List<CODES>();
CODES obj;

int boardnumber = 0;
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 5; i++)
{
boardnumber++;
obj = new CODES();
obj.Init();
obj.X = obj.X + (j * 150);
obj.Y = obj.Y + (i * 70);
obj.BoardNumber = boardnumber;
ListCodes.Add(obj);
}
}
}

Regards Thomas



private void MapMillimetersToPixels(Graphics gfx, Rectangle
rectPixels, Rectangle rectMm)
{
Matrix matrix = new Matrix();
ScaleX = (float)rectPixels.Width / rectMm.Width;
ScaleY = (float)rectPixels.Height / rectMm.Height;
matrix.Scale(ScaleX, ScaleY);
matrix.Translate(rectPixels.Left - ScaleX * rectMm.Left,
rectPixels.Top - ScaleY * rectMm.Top);

gfx.Transform = matrix;
}
 
P

Peter Duniho

how can I make the transformation matrix?
Zero point
Left top
Left bottom
Right top
Right bottom

This is related to your other thread, I assume.

The key here is to set the appropriate rectMM before calling the
Map...() method.

For example:

bool fZeroLeft, fZeroTop;

where these two flags indicate which side of the rectangle is the
origin. If they are both set, the origin is the left and top, if
neither is set, the origin is the right and bottom, etc.

Then:

int mmWidth, mmHeight;
Rectangle rectMM;

You should already know the width and height of the device, of course.
Those values will be in the mmWidth and mmHeight variables. We will
initialize rectMM as appropriate:

rectMM = new Rect(
new Point(fZeroLeft ? 0 : -mmWidth,
fZeroTop ? 0: -mmHeight),
new Size(fZeroLeft ? mmWidth : -mmWidth,
fZeroTop ? mmHeight : -mmHeight));

Then if you pass that rectMM into the Map...() method, it should
configure the transformation matrix appropriately.

Granted, I haven't actually tested any of this. You may have to
adjust some of the code to get it to work exactly right. But this is
the basic theory.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Matrix - Transformation 15

Top