Re: Matrix - Transformation

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

I will try it to explain exactly, what I need

List
P1 10,10
P2 10,90
P3 400,10
P4 400,90
or more points

Depend from the zero point

Case 1

(900mm,900mm)
--------------------------------------
|....................................|
|...........P4....................P2.|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|...........P3....................P1.|
--------------------------------------(0,0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Case 2
(900mm,900mm)
--------------------------------------
|....................................|
|.P2..................P4.............|
|....................................|
|....................................|
|....................................|
|....................................|
|.P1..................P3.............|
|....................................|
--------------------------------------
0,0


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Case 3
0,0
--------------------------------------
|....................................|
|........P3..................... P1.|
|....................................|
|....................................|
|....................................|
|....................................|
|........P4.......................P2.|
|....................................|
--------------------------------------
900mm,900mm


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Case 4

0,0
--------------------------------------
|....................................|
|.P1................. P3.............|
|....................................|
|....................................|
|....................................|
|....................................|
|.P2..................P4.............|
|....................................|
--------------------------------------(900mm,900mm)

How can I nmake that?
With matrix tranformation mirror?

Best Regards Thomas

The code at moment is

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace Grafik
{
public partial class Form1 : Form
{
public List<CODES> ListCodes;

public class CODES
{
private double x;
private double y;

private int boardNumber;

public double X
{
get { return x; }
set { x = value; }
}

public double Y
{
get { return y; }
set { y = value; }
}

public int BoardNumber
{
get { return boardNumber; }
set { boardNumber = value; }
}

public void Init()
{
X = 0;
Y = 0;
boardNumber = 0;
}
}

public Form1()
{
InitializeComponent();
}

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);
}
}
}

float ScaleX, ScaleY;

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

gfx.Transform = matrix;
}

private int MillimetersToPixels_X(double value)
{
return Convert.ToInt32(ScaleX * value);
}

private int MillimetersToPixels_Y(double value)
{
return Convert.ToInt32(ScaleY * value);
}

public void DrawPanel(List<CODES> listCodes, PaintEventArgs e)
{
Graphics gfx; // the Graphics instance; for example, taken from
PaintEventArgs
gfx = e.Graphics;


PointF ptCur;
string strPoint;

ptCur = new PointF();
foreach ( CODES code in listCodes )
{
ptCur.X = MillimetersToPixels_Y(code.X);
ptCur.Y = MillimetersToPixels_Y(code.Y);
ptCur.X = (float)code.X;
ptCur.Y = (float)code.Y;

// These two lines of code draw the cross
gfx.DrawLine( Pens.Black, ptCur.X - 5, ptCur.Y, ptCur.X +
5,ptCur.Y );
gfx.DrawLine( Pens.Black, ptCur.X, ptCur.Y - 5,
ptCur.X,ptCur.Y + 5 );

// This block of code draws the label for the point
using ( Brush brush = new SolidBrush( ForeColor ) )
{
strPoint = "P" + code.BoardNumber + "(" + code.X +","
+code.Y + ")";
gfx.DrawString( strPoint, Font, brush, ptCur.X +
10,ptCur.Y );
}
}


// calculation is finished -- now tranformation from mm to pixel


gfx.DrawRectangle(Pens.Red, 5, 5, 480, 380);


Rectangle rectMM; //= new Rectangle(0, 0, 900, 500);
Rectangle rectPixel = new Rectangle();
bool fZeroLeft, fZeroTop;
fZeroLeft = false;
fZeroTop = false;

int mmWidth, mmHeight;
mmWidth = 900;
mmHeight = 500;
rectMM = new Rectangle(
new Point(fZeroLeft ? 0 : -mmWidth,
fZeroTop ? 0 : -mmHeight),
new Size(fZeroLeft ? mmWidth : -mmWidth,
fZeroTop ? mmHeight : -mmHeight));

rectPixel = panel_draw.DisplayRectangle;

MapMillimetersToPixels( gfx, rectPixel, rectMM );


}

private void panel_draw_Paint(object sender, PaintEventArgs e)
{
DrawPanel(ListCodes, e);
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What is not working at moment?

#### --> means --> is the windows panel --> panel_draw
#### the relation between the dimension from the mm to the pixel
#### is not ok.

(900mm,900mm)
###############################################
--------------------------------------~~~~~~~~#
|....................................|~~~~~~~~#
|...........P4....................P2.|~~~~~~~~#
|....................................|~~~~~~~~#
|....................................|~~~~~~~~#
|....................................|~~~~~~~~#
|....................................|~~~~~~~~#
|....................................|~~~~~~~~#
|...........P3....................P1.|~~~~~~~~#
--------------------------------------(0,0)~~~#
###############################################

.



Relevant Pages

  • Re: C#- coordinate system, drawing
    ... public class CODES ... private double x; ... public int BoardNumber ... private void MapMillimetersToPixels(Graphics gfx, Rectangle ...
    (microsoft.public.dotnet.languages.csharp)
  • [Newbie] DirectSound Latency
    ... I'm writing a program to read data from microphone, modify them with ... private SecondaryBuffer p_buf; ... private int captureBufferSize; ... private void processaDaBuffer { ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: This program is not thread safe and cause run time error in debug mode
    ... As I have written this error appear only in debug mode and not in release ... private void start_Click ... private void RefreshTime(int hh, int mm, int ss) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Disappearing Controls when the designer loads a form.
    ... > user controls which inherit ... > first if you just drop it on the TabPage, save, and close the designer ... > private ArrayList readOnlyColumnsList; ... > private void grid_BeforeEnterEditMode ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: explanation of when need to repopulate control
    ... i removed the main parent dropdown and only left the 2 below it. ... > composite controls from my composite control so that there is only drop ... > private void fasFiscalAgent_FiscalAgentChanged ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)