Matrix - Transformation

T

Thomas Bauer

Hello,

I search a example like that.

(1,0,0,1,4,5 ) -- moving
(1,0,0,1,0,0 ) -- normal matrix
(-1,0,0,1,0,0 ) -- Mirror Y-Axis
(0,-1,0,1,0,0 ) -- Mirror X-Axis

I caluculate all in mm.
After then, I want to make a transformation.

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


The zero point.
left
right
top or bottom
All corners are possible, so I need a Matrox multiplication, or?
I prefer a transformation, but I haven't here experience.
So my example is without transformation matrix.

Best regards and thanks for your help
Thomas




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

namespace Panel
{
public partial class Form1 : Form
{
public List<Codes> listCodes;

/// <summary>Die Farbe, mit der die Buchstaben
/// neben dem Kreuz gezeichnet werden</summary>
Brush brush;

int anzX = 4;
int anzY = 5;
int abstandX = 50;
int abstandY = 30;

/// <summary>Radius des Kreuzes</summary>
int kRad = 5;

/// <summary>X-Abstand der Buchstaben vom Punkt</summary>
int xPunktAbstand = 10;

/// <summary>Skalierung der gesamten Grafik. 1=nicht
skaliert.</summary>
float gesamtSkalierung = 1;

float fontGrössePunktBeschreibung = 6.0F;
Font punktBeschreibungsFont;

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 PointF GetPointF()
{
return new PointF((float)x, (float)y);
}

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

public Codes(double x, double y, int boardNumber)
{
this.x = x;
this.y = y;
this.boardNumber = boardNumber;
}
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
ListCodesFüllen(ref listCodes, anzX, anzY, abstandX,
abstandY);
//brush = new SolidBrush(this.ForeColor);
brush = new SolidBrush(Color.Red);

punktBeschreibungsFont = new Font("Arial",
fontGrössePunktBeschreibung);
}

private void ListCodesFüllen(ref List<Codes> listCodes, int
anzX, int anzY, int abstandX, int abstandY)
{
listCodes = new List<Codes>();
Codes codes; int boardNumber = 0;

for (int x = 0; x < anzX; x++)
{
for (int y = 0; y < anzY; y++)
{
boardNumber++;
codes = new Codes(x * abstandX, y * abstandY,
boardNumber);
listCodes.Add(codes);
}
}
}

public void DrawPanel(List<Codes> listCodes, PaintEventArgs e)
{
Graphics g = e.Graphics;
PointF ptCur;
string strPoint;
// momentan keine Auswirkung
g.ScaleTransform(gesamtSkalierung, gesamtSkalierung);

ptCur = new PointF();
foreach (Codes code in listCodes)
{
ptCur = MillimeterToPixelPointF(g, code.GetPointF());

// Zeichnen der zwei Linien, die das Kreuz bilden
g.DrawLine(Pens.Black, ptCur.X - kRad, ptCur.Y,
ptCur.X + kRad, ptCur.Y);
g.DrawLine(Pens.Black, ptCur.X, ptCur.Y - kRad,
ptCur.X, ptCur.Y + kRad);

// Buchstaben und Bezeichnungen für den Punkt zeichnen
strPoint = "P" + code.BoardNumber + "(" + code.X + ","
+ code.Y + ")";
//g.DrawString(strPoint, Font, brush, ptCur.X +
xPunktAbstand, ptCur.Y);
g.DrawString(strPoint, punktBeschreibungsFont, brush,
ptCur.X + xPunktAbstand, ptCur.Y);
}

ZeichneAuswahlRechteck(g, 1, 1, 2, 2);
}

private void ZeichneAuswahlRechteck(Graphics g, int links, int
rechts, int breite, int höhe)
{
Point p1 = Point.Ceiling(MillimeterToPixelPointF(
g, new PointF(links * abstandX, rechts * abstandY)));
Point p2 = Point.Ceiling(MillimeterToPixelPointF(
g, new PointF(breite * abstandX, höhe * abstandY)));
Rectangle r = new Rectangle(p1.X, p1.Y, p2.X, p2.Y);
g.DrawRectangle(Pens.Red, r);
}

float zollAlsMillimeter = 25.4F;

PointF MillimeterToPixelPointF(Graphics g, PointF p)
{
p.X *= g.DpiX / zollAlsMillimeter;
p.Y *= g.DpiY / zollAlsMillimeter;
return p;
}

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

}
 
P

Peter Duniho

[...]
All corners are possible, so I need a Matrox multiplication, or?
I prefer a transformation, but I haven't here experience.
So my example is without transformation matrix.

How is this different from your previous question? Why are you
starting a new thread? What about the information provided to you so
far is not working for you?

For what it's worth, IMHO you are not doing a very good job asking
effective questions. You will receive better results if you work
harder to express your questions in a simple, readable way and keep
your questions in a single thread when they are related to questions
you've already asked. I can't speak for others, but I'm having a very
hard time following what it is exactly you're asking.

Pete
 
T

Thomas Bauer

Hello Peter,
How is this different from your previous question?
I have problems with my zero points. Sorry, please not angry with me.
I need a solution.

0,0 (900mm,900mm) 0,0
--------------------------------------
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
--------------------------------------0,0(900mm,900mm)
0,0

I think we can solve this over matrix transformation, like this.
(1,0,0,1,4,5 ) -- moving
(1,0,0,1,0,0 ) -- normal matrix
(-1,0,0,1,0,0 ) -- Mirror Y-Axis
(0,-1,0,1,0,0 ) -- Mirror X-Axis

I would like to paint only the points, as a function of the zero
point.
Matrix:
(x,y,z,scalefactor,MovingX,MovingY)
z is every time 0 in my example

(-1,0,0,1,0,0 ) -- Mirror Y-Axis
(0,-1,0,1,0,0 ) -- Mirror X-Axis

I need here maybe a matrix multiplication.
It is missing to me at the conversion.
Perhaps you help me still or someone else.

Thank you and many greet Thomas
 
P

Peter Duniho

I have problems with my zero points. Sorry, please not angry with
me.I need a solution.

I'm not angry with you. But I feel like I've already answered the
question and don't understand why you keep asking it. If there's
something wrong with the answer that was given, you should reply to
that answer and explain what was wrong. Please stop creating new
threads that are asking the same question.

Pete
 
T

Thomas Bauer

Hello Pete
I'm not angry with you. But I feel like I've already answered the
question and don't understand why you keep asking it. If there's
something wrong with the answer that was given, you should reply to
that answer and explain what was wrong. Please stop creating new
threads that are asking the same question.
wrong is the zero point. It is not working. The relation pixel to mm
is not correct.
Maybe you can test it.


Regards Thomas
 
P

Peter Duniho

Hello Pete
wrong is the zero point. It is not working. The relation pixel to mm
is not correct.
Maybe you can test it.

I can't test it without code. Please post a concise-but-complete
example of code that reliably demonstrates the problem. There will be
the added complication because it's a form. If you can, try to make a
single file that has everything and post the contents of that.

Barring that, post all of the .cs files from your project. Please make
VERY certain that there is NOTHING in the code you post that is not
absolutely required in order to demonstrate the problem. This means it
should pretty much contain only the code for the form and/or a control
into which the actual drawing is done. You can hardcode some test data
to draw what you need.

Pete
 
T

Thomas Bauer

Hello Peter,

ok thanks.
Here the code. I make two tests.

You need only a panel
this.panel_draw = new System.Windows.Forms.Panel();

Regards Thomas


First test.
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);
}
}
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Second test -- the font is here ok
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Panel
{
public partial class Form1 : Form
{
public List<Codes> listCodes;

/// <summary>Die Farbe, mit der die Buchstaben
/// neben dem Kreuz gezeichnet werden</summary>
Brush brush;

int anzX = 4;
int anzY = 5;
int abstandX = 50;
int abstandY = 30;

/// <summary>Radius des Kreuzes</summary>
int kRad = 5;

/// <summary>X-Abstand der Buchstaben vom Punkt</summary>
int xPunktAbstand = 10;

/// <summary>Skalierung der gesamten Grafik. 1=nicht
skaliert.</summary>
float gesamtSkalierung = 1;

float fontGrössePunktBeschreibung = 6.0F;
Font punktBeschreibungsFont;

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 PointF GetPointF()
{
return new PointF((float)x, (float)y);
}

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

public Codes(double x, double y, int boardNumber)
{
this.x = x;
this.y = y;
this.boardNumber = boardNumber;
}
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
ListCodesFüllen(ref listCodes, anzX, anzY, abstandX,
abstandY);
//brush = new SolidBrush(this.ForeColor);
brush = new SolidBrush(Color.Red);

punktBeschreibungsFont = new Font("Arial",
fontGrössePunktBeschreibung);
}

private void ListCodesFüllen(ref List<Codes> listCodes, int
anzX, int anzY, int abstandX, int abstandY)
{
listCodes = new List<Codes>();
Codes codes; int boardNumber = 0;

for (int x = 0; x < anzX; x++)
{
for (int y = 0; y < anzY; y++)
{
boardNumber++;
codes = new Codes(x * abstandX, y * abstandY,
boardNumber);
listCodes.Add(codes);
}
}
}

public void DrawPanel(List<Codes> listCodes, PaintEventArgs e)
{
Graphics g = e.Graphics;
PointF ptCur;
string strPoint;
// momentan keine Auswirkung
g.ScaleTransform(gesamtSkalierung, gesamtSkalierung);

ptCur = new PointF();
foreach (Codes code in listCodes)
{
ptCur = MillimeterToPixelPointF(g, code.GetPointF());

// Zeichnen der zwei Linien, die das Kreuz bilden
g.DrawLine(Pens.Black, ptCur.X - kRad, ptCur.Y,
ptCur.X + kRad, ptCur.Y);
g.DrawLine(Pens.Black, ptCur.X, ptCur.Y - kRad,
ptCur.X, ptCur.Y + kRad);

// Buchstaben und Bezeichnungen für den Punkt zeichnen
strPoint = "P" + code.BoardNumber + "(" + code.X + ","
+ code.Y + ")";
//g.DrawString(strPoint, Font, brush, ptCur.X +
xPunktAbstand, ptCur.Y);
g.DrawString(strPoint, punktBeschreibungsFont, brush,
ptCur.X + xPunktAbstand, ptCur.Y);
}

ZeichneAuswahlRechteck(g, 1, 1, 2, 2);
}

private void ZeichneAuswahlRechteck(Graphics g, int links, int
rechts, int breite, int höhe)
{
Point p1 = Point.Ceiling(MillimeterToPixelPointF(
g, new PointF(links * abstandX, rechts * abstandY)));
Point p2 = Point.Ceiling(MillimeterToPixelPointF(
g, new PointF(breite * abstandX, höhe * abstandY)));
Rectangle r = new Rectangle(p1.X, p1.Y, p2.X, p2.Y);
g.DrawRectangle(Pens.Red, r);
}

float zollAlsMillimeter = 25.4F;

PointF MillimeterToPixelPointF(Graphics g, PointF p)
{
p.X *= g.DpiX / zollAlsMillimeter;
p.Y *= g.DpiY / zollAlsMillimeter;
return p;
}

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

}
 
P

Peter Duniho

Hello Peter,

ok thanks.
Here the code. I make two tests.

I don't understand. Which test demonstrates the issue you're asking
about? What is the exact behavior you expect, and how does that differ
from the behavior you're seeing?
 
T

Thomas Bauer

Hello,

test no. 1 with
Rectangle rectMM = new Rectangle(0, 0, 900, 500);
and the windows panel panel_draw have the coodinates as pixel.

So the relation looks not ok. (mm to pixel)
And the main problem are the zero point.
I prefer a solution like that with a matrix.
Transformation....?

0,0 (900mm,900mm) 0,0
--------------------------------------
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
|....................................|
--------------------------------------0,0(900mm,900mm)
0,0


I think we can solve this over matrix transformation, like this.
(1,0,0,1,4,5 ) -- moving
(1,0,0,1,0,0 ) -- normal matrix
(-1,0,0,1,0,0 ) -- Mirror Y-Axis
(0,-1,0,1,0,0 ) -- Mirror X-Axis


I would like to paint only the points, as a function of the zero
point.
Matrix:
(x,y,z,scalefactor,MovingX,MovingY)
z is every time 0 in my example


(-1,0,0,1,0,0 ) -- Mirror Y-Axis
(0,-1,0,1,0,0 ) -- Mirror X-Axis



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

test no. 2 is only for the font.

regards Thomas
 
P

Peter Duniho

test no. 1 with
Rectangle rectMM = new Rectangle(0, 0, 900, 500);
and the windows panel panel_draw have the coodinates as pixel.

I'm sorry. You aren't answering my questions. Instead, you keep
reposting basically the same thing over and over. I can't help you.
Hopefully, someone else will take up the cause.
 
T

Thomas Bauer

Hello,
is it possible I send you an eMail?
Or you send me an eMail? eingang11arcor.de
Is easier, if you see a picture, or?

Regards Thomas
 
T

Thomas Bauer

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)~~~#
###############################################
 
T

Thomas Bauer

Hello Peter,
you are angry with me, correct?
I did not want that. Well, I wanted only to show the problem
definition.
In completely form.
It say ud simply can whether you still help or not?
Can you say simply whether you still help or not?
I know the transformation is complicated, nevertheless it would be
nicely for tip
or you can recommend a good book
- Matrix
-Transformation
in C#
I must solve simply the problem, it is important for me.

Thanks and have a nice day / evening.

Regards Thomas
 
P

Peter Duniho

Hello Peter,
you are angry with me, correct?

I am not angry. I've simply recognized that I do not have the skills
necessary to help you resolve your question. I am not interested in
repeating the same thing over and over again, and we have what seems to
me to be an unresolvable communication gap.

Whether this is strictly because of the difference in native languages,
or there is something else going on, I can't say. But not only am I
having difficulty understanding you, you seem to be having difficulty
understanding me. I've posted a number of messages that should have
answered the question as I understand it, but you keep posting new
messages that don't seem at all relevant to the solution I've offered.

You really should just find someone who speaks a language in which
you're fluent (German?) who has the knowledge to help you. If I
understand your problem correctly, it's not really that hard, so it's
not at all true that I'm the only person around who could answer the
question.

There are language-specific newsgroups for a variety of Microsoft
technologies, and I believe that includes C# and .NET. Have you tried
one of those?

I'm sorry I couldn't be of more help. But the fact is, I believe I
can't be. There's not any point in me trying to be.

Pete
 
T

Thomas Bauer

Hello Pete,
is ok, I try my last question.
Maybe you help me. It is your decision.

I have problems from mm to pixel.
float scaleX = (float)panel_draw.DisplayRectangle.Width /
Math.Abs(fWidth);
float scaleY = (float)panel_draw.DisplayRectangle.Height /
Math.Abs(fHeight);
Here is a mistake.

The user coordinates are 0,0,900,500 in mm
I want to draw it inside the windows panel panel_draw. Not more.

I prefer the zero point like this.
case Origin.BottomRight:
{
Matrix m = new Matrix();
m.Translate(fWidth - 1, fHeight - 1);
m.Scale(-1, -1);
e.Graphics.Transform = m;
break;
}
It is good for overview.


In appendix the project.

Regards Thomas



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

namespace ucProductlistView
{
public partial class ucProductlistView : UserControl
{
//
*****************************************************************************
public enum Origin
{
TopLeft,
TopRight,
BottomLeft,
BottomRight
}
//--------------------------------------------------------------------------
const float fX = 0;
const float fY = 0;
const float fWidth = 900;
const float fHeight = 500;


#region Punkte Liste
public List<Codes> listCodes;

/// <summary>Die Farbe, mit der die Buchstaben
/// neben dem Kreuz gezeichnet werden</summary>
Brush brush;

int anzX = 4;
int anzY = 5;
int abstandX = 50;
int abstandY = 30;

/// <summary>Radius des Kreuzes</summary>
int kRad = 5;

/// <summary>X-Abstand der Buchstaben vom Punkt</summary>
int xPunktAbstand = 10;

/// <summary>Skalierung der gesamten Grafik. 1=nicht
skaliert.</summary>
float gesamtSkalierung = 1;

float fontGrössePunktBeschreibung = 6.0F;
Font punktBeschreibungsFont;

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 PointF GetPointF()
{
return new PointF((float)x, (float)y);
}

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

public Codes(double x, double y, int boardNumber)
{
this.x = x;
this.y = y;
this.boardNumber = boardNumber;
}
}
#endregion

Origin _origin = Origin.TopLeft;

public ucProductlistView()
{
InitializeComponent();

ListCodesFüllen(ref listCodes, anzX, anzY, abstandX,
abstandY);
//brush = new SolidBrush(this.ForeColor);
brush = new SolidBrush(Color.Red);

punktBeschreibungsFont = new Font("Arial",
fontGrössePunktBeschreibung);
}

private void ListCodesFüllen(ref List<Codes> listCodes, int
anzX, int anzY, int abstandX, int abstandY)
{
listCodes = new List<Codes>();
Codes codes;
int boardNumber = 0;

for (int x = 0; x < anzX; x++)
{
for (int y = 0; y < anzY; y++)
{
boardNumber++;
codes = new Codes(x * abstandX, y * abstandY,
boardNumber);
listCodes.Add(codes);
}
}
}

float zollAlsMillimeter = 25.4F;

PointF MillimeterToPixelPointF(Graphics g, PointF p)
{
p.X *= g.DpiX / zollAlsMillimeter;
p.Y *= g.DpiY / zollAlsMillimeter;
return p;
}

private void panel_draw_Paint(object sender, PaintEventArgs e)
{
_origin = Origin.TopRight;

base.OnPaint(e);

Graphics g = e.Graphics;
PointF ptCur;
string strPoint;
// momentan keine Auswirkung
g.ScaleTransform(gesamtSkalierung, gesamtSkalierung);

ptCur = new PointF();
foreach (Codes code in listCodes)
{
ptCur = MillimeterToPixelPointF(g, code.GetPointF());

// Zeichnen der zwei Linien, die das Kreuz bilden
g.DrawLine(Pens.Black, ptCur.X - kRad, ptCur.Y,
ptCur.X + kRad, ptCur.Y);
g.DrawLine(Pens.Black, ptCur.X, ptCur.Y - kRad,
ptCur.X, ptCur.Y + kRad);

// Buchstaben und Bezeichnungen für den Punkt zeichnen
strPoint = "P" + code.BoardNumber + "(" + code.X + ","
+ code.Y + ")";
//g.DrawString(strPoint, Font, brush, ptCur.X +
xPunktAbstand, ptCur.Y);
g.DrawString(strPoint, punktBeschreibungsFont, brush,
ptCur.X + xPunktAbstand, ptCur.Y);
}



float scaleX = (float)panel_draw.DisplayRectangle.Width /
Math.Abs(fWidth);
float scaleY = (float)panel_draw.DisplayRectangle.Height /
Math.Abs(fHeight);

switch (_origin)
{
case Origin.TopLeft:
{
Matrix m = new Matrix();
m.Translate(0, 0);
m.Scale(1, 1);
e.Graphics.Transform = m;
break;
}
case Origin.TopRight:
{
Matrix m = new Matrix();
m.Translate(fWidth - 1, 0);
//m.Scale(-1, 1);
m.Scale(scaleX, scaleY);
e.Graphics.Transform = m;
break;
}
case Origin.BottomLeft:
{
Matrix m = new Matrix();
m.Translate(0, fHeight - 1);
m.Scale(1, -1);
e.Graphics.Transform = m;
break;
}
case Origin.BottomRight:
{
Matrix m = new Matrix();
m.Translate(fWidth - 1, fHeight - 1);
m.Scale(-1, -1);
e.Graphics.Transform = m;
break;
}
}

}
}
}
 

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

Top