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 make that?
With matrix tranformation mirror?
Best Regards Thomas
The code at moment is
You need only a panel
this.panel_draw = new System.Windows.Forms.Panel();
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)~~~#
###############################################
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.
Answers
Know the answer? Post it. Somebody with the same question will find it here.