Matrix - Transformation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Bauer

    Matrix - Transformation

    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 MapMillimetersT oPixels(Graphic s gfx, Rectangle
    rectPixels, Rectangle rectMm)
    {
    Matrix matrix = new Matrix();
    ScaleX = (float)rectPixe ls.Width / Math.Abs(rectMm .Width);
    ScaleY = (float)rectPixe ls.Height /
    Math.Abs(rectMm .Height);
    matrix.Scale(Sc aleX, ScaleY);
    matrix.Translat e(rectPixels.Le ft - 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.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows. Forms;

    namespace Panel
    {
    public partial class Form1 : Form
    {
    public List<CodeslistC odes;

    /// <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>Radi us des Kreuzes</summary>
    int kRad = 5;

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

    /// <summary>Skalie rung der gesamten Grafik. 1=nicht
    skaliert.</summary>
    float gesamtSkalierun g = 1;

    float fontGrössePunkt Beschreibung = 6.0F;
    Font punktBeschreibu ngsFont;

    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.boardNumbe r = boardNumber;
    }
    }

    public Form1()
    {
    InitializeCompo nent();
    }

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

    punktBeschreibu ngsFont = new Font("Arial",
    fontGrössePunkt Beschreibung);
    }

    private void ListCodesFüllen (ref List<CodeslistC odes, 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(c odes);
    }
    }
    }

    public void DrawPanel(List< CodeslistCodes, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    PointF ptCur;
    string strPoint;
    // momentan keine Auswirkung
    g.ScaleTransfor m(gesamtSkalier ung, gesamtSkalierun g);

    ptCur = new PointF();
    foreach (Codes code in listCodes)
    {
    ptCur = MillimeterToPix elPointF(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.BoardNumbe r + "(" + code.X + ","
    + code.Y + ")";
    //g.DrawString(st rPoint, Font, brush, ptCur.X +
    xPunktAbstand, ptCur.Y);
    g.DrawString(st rPoint, punktBeschreibu ngsFont, brush,
    ptCur.X + xPunktAbstand, ptCur.Y);
    }

    ZeichneAuswahlR echteck(g, 1, 1, 2, 2);
    }

    private void ZeichneAuswahlR echteck(Graphic s g, int links, int
    rechts, int breite, int höhe)
    {
    Point p1 = Point.Ceiling(M illimeterToPixe lPointF(
    g, new PointF(links * abstandX, rechts * abstandY)));
    Point p2 = Point.Ceiling(M illimeterToPixe lPointF(
    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 zollAlsMillimet er = 25.4F;

    PointF MillimeterToPix elPointF(Graphi cs g, PointF p)
    {
    p.X *= g.DpiX / zollAlsMillimet er;
    p.Y *= g.DpiY / zollAlsMillimet er;
    return p;
    }

    private void panel_draw_Pain t(object sender, PaintEventArgs e)
    {
    DrawPanel(listC odes, e);
    }
    }

    }

  • Peter Duniho

    #2
    Re: Matrix - Transformation

    In article
    <1193591207.289 659.324400@22g2 000hsm.googlegr oups.com>Thomas Bauer
    <mail3232@arcor .dewrote:
    [...]
    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

    --
    I'm trying a new usenet client for Mac, Nemo OS X.
    You can download it at http://www.malcom-mac.com/nemo

    Comment

    • Thomas Bauer

      #3
      Re: Matrix - Transformation

      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,scalefac tor,MovingX,Mov ingY)
      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

      Comment

      • Peter Duniho

        #4
        Re: Matrix - Transformation

        In article
        <1193598424.192 868.294910@o38g 2000hse.googleg roups.com>Thoma s Bauer
        <mail3232@arcor .dewrote:
        > 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.
        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

        --
        I'm trying a new usenet client for Mac, Nemo OS X.
        You can download it at http://www.malcom-mac.com/nemo

        Comment

        • Thomas Bauer

          #5
          Re: Matrix - Transformation

          Hello Pete
          >> 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.
          >
          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

          Comment

          • Thomas Bauer

            #6
            Re: Matrix - Transformation

            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.Collecti ons.Generic;
            using System.Componen tModel;
            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<CODESListC odes;

            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()
            {
            InitializeCompo nent();
            }

            private void Form1_Load(obje ct 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(o bj);
            }
            }
            }

            float ScaleX, ScaleY;

            private void MapMillimetersT oPixels(Graphic s gfx, Rectangle
            rectPixels, Rectangle rectMm)
            {
            Matrix matrix = new Matrix();
            ScaleX = (float)rectPixe ls.Width / Math.Abs(rectMm .Width);
            ScaleY = (float)rectPixe ls.Height /
            Math.Abs(rectMm .Height);
            matrix.Scale(Sc aleX, ScaleY);
            matrix.Translat e(rectPixels.Le ft - ScaleX * rectMm.Left,
            rectPixels.Top - ScaleY * rectMm.Top);

            gfx.Transform = matrix;
            }

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

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

            public void DrawPanel(List< CODESlistCodes, 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 = MillimetersToPi xels_Y(code.X);
            ptCur.Y = MillimetersToPi xels_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.BoardNumbe r + "(" + code.X +","
            +code.Y + ")";
            gfx.DrawString( strPoint, Font, brush, ptCur.X +
            10,ptCur.Y );
            }
            }


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


            gfx.DrawRectang le(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.Disp layRectangle;

            MapMillimetersT oPixels( gfx, rectPixel, rectMM );


            }

            private void panel_draw_Pain t(object sender, PaintEventArgs e)
            {
            DrawPanel(ListC odes, e);
            }
            }
            }

            ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~
            Second test -- the font is here ok
            using System;
            using System.Collecti ons.Generic;
            using System.Componen tModel;
            using System.Data;
            using System.Drawing;
            using System.Text;
            using System.Windows. Forms;

            namespace Panel
            {
            public partial class Form1 : Form
            {
            public List<CodeslistC odes;

            /// <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>Radi us des Kreuzes</summary>
            int kRad = 5;

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

            /// <summary>Skalie rung der gesamten Grafik. 1=nicht
            skaliert.</summary>
            float gesamtSkalierun g = 1;

            float fontGrössePunkt Beschreibung = 6.0F;
            Font punktBeschreibu ngsFont;

            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.boardNumbe r = boardNumber;
            }
            }

            public Form1()
            {
            InitializeCompo nent();
            }

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

            punktBeschreibu ngsFont = new Font("Arial",
            fontGrössePunkt Beschreibung);
            }

            private void ListCodesFüllen (ref List<CodeslistC odes, 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(c odes);
            }
            }
            }

            public void DrawPanel(List< CodeslistCodes, PaintEventArgs e)
            {
            Graphics g = e.Graphics;
            PointF ptCur;
            string strPoint;
            // momentan keine Auswirkung
            g.ScaleTransfor m(gesamtSkalier ung, gesamtSkalierun g);

            ptCur = new PointF();
            foreach (Codes code in listCodes)
            {
            ptCur = MillimeterToPix elPointF(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.BoardNumbe r + "(" + code.X + ","
            + code.Y + ")";
            //g.DrawString(st rPoint, Font, brush, ptCur.X +
            xPunktAbstand, ptCur.Y);
            g.DrawString(st rPoint, punktBeschreibu ngsFont, brush,
            ptCur.X + xPunktAbstand, ptCur.Y);
            }

            ZeichneAuswahlR echteck(g, 1, 1, 2, 2);
            }

            private void ZeichneAuswahlR echteck(Graphic s g, int links, int
            rechts, int breite, int höhe)
            {
            Point p1 = Point.Ceiling(M illimeterToPixe lPointF(
            g, new PointF(links * abstandX, rechts * abstandY)));
            Point p2 = Point.Ceiling(M illimeterToPixe lPointF(
            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 zollAlsMillimet er = 25.4F;

            PointF MillimeterToPix elPointF(Graphi cs g, PointF p)
            {
            p.X *= g.DpiX / zollAlsMillimet er;
            p.Y *= g.DpiY / zollAlsMillimet er;
            return p;
            }

            private void panel_draw_Pain t(object sender, PaintEventArgs e)
            {
            DrawPanel(listC odes, e);
            }
            }

            }


            Comment

            • Peter Duniho

              #7
              Re: Matrix - Transformation

              On 2007-10-29 00:57:58 -0700, Thomas Bauer <mail3232@arcor .desaid:
              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?

              Comment

              • Thomas Bauer

                #8
                Re: Matrix - Transformation

                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,scalefac tor,MovingX,Mov ingY)
                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 MapMillimetersT oPixels(Graphic s gfx, Rectangle
                rectPixels, Rectangle rectMm)
                {
                Matrix matrix = new Matrix();
                ScaleX = (float)rectPixe ls.Width /
                Math.Abs(rectMm .Width);
                ScaleY = (float)rectPixe ls.Height /
                Math.Abs(rectMm .Height);
                matrix.Scale(Sc aleX, ScaleY);
                matrix.Translat e(rectPixels.Le ft - ScaleX * rectMm.Left,
                rectPixels.Top - ScaleY * rectMm.Top);


                gfx.Transform = matrix;
                }

                test no. 2 is only for the font.

                regards Thomas

                Comment

                • Peter Duniho

                  #9
                  Re: Matrix - Transformation

                  On 2007-10-29 11:56:45 -0700, Thomas Bauer <mail3232@arcor .desaid:
                  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.

                  Comment

                  • Thomas Bauer

                    #10
                    Re: Matrix - Transformation

                    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

                    Comment

                    • Thomas Bauer

                      #11
                      Re: Matrix - Transformation

                      Hello,
                      is it possible I send you an eMail?
                      Or you send me an eMail? eingang11arcor. de
                      --eingang11@arcor .de Thanks
                      Is easier, if you see a picture, or?
                      >
                      Regards Thomas


                      Comment

                      • Thomas Bauer

                        #12
                        Re: Matrix - Transformation

                        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.Collecti ons.Generic;
                        using System.Componen tModel;
                        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<CODESListC odes;

                        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()
                        {
                        InitializeCompo nent();
                        }

                        private void Form1_Load(obje ct 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(o bj);
                        }
                        }
                        }

                        float ScaleX, ScaleY;

                        private void MapMillimetersT oPixels(Graphic s gfx, Rectangle
                        rectPixels, Rectangle rectMm)
                        {
                        Matrix matrix = new Matrix();
                        ScaleX = (float)rectPixe ls.Width / Math.Abs(rectMm .Width);
                        ScaleY = (float)rectPixe ls.Height /
                        Math.Abs(rectMm .Height);
                        matrix.Scale(Sc aleX, ScaleY);
                        matrix.Translat e(rectPixels.Le ft - ScaleX * rectMm.Left,
                        rectPixels.Top - ScaleY * rectMm.Top);

                        gfx.Transform = matrix;
                        }

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

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

                        public void DrawPanel(List< CODESlistCodes, 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 = MillimetersToPi xels_Y(code.X);
                        ptCur.Y = MillimetersToPi xels_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.BoardNumbe r + "(" + code.X +","
                        +code.Y + ")";
                        gfx.DrawString( strPoint, Font, brush, ptCur.X +
                        10,ptCur.Y );
                        }
                        }


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


                        gfx.DrawRectang le(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.Disp layRectangle;

                        MapMillimetersT oPixels( gfx, rectPixel, rectMM );


                        }

                        private void panel_draw_Pain t(object sender, PaintEventArgs e)
                        {
                        DrawPanel(ListC odes, 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)~~~#
                        ############### ############### ############### ##

                        Comment

                        • Thomas Bauer

                          #13
                          Re: Matrix - Transformation

                          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

                          Comment

                          • Peter Duniho

                            #14
                            Re: Matrix - Transformation

                            On 2007-11-01 10:42:15 -0700, Thomas Bauer <mail3232@arcor .desaid:
                            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

                            Comment

                            • Thomas Bauer

                              #15
                              Re: Matrix - Transformation

                              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_dr aw.DisplayRecta ngle.Width /
                              Math.Abs(fWidth );
                              float scaleY = (float)panel_dr aw.DisplayRecta ngle.Height /
                              Math.Abs(fHeigh t);
                              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.BottomRi ght:
                              {
                              Matrix m = new Matrix();
                              m.Translate(fWi dth - 1, fHeight - 1);
                              m.Scale(-1, -1);
                              e.Graphics.Tran sform = m;
                              break;
                              }
                              It is good for overview.


                              In appendix the project.

                              Regards Thomas



                              using System;
                              using System.Collecti ons.Generic;
                              using System.Componen tModel;
                              using System.Drawing;
                              using System.Data;
                              using System.Text;
                              using System.Windows. Forms;
                              using System.Drawing. Drawing2D;

                              namespace ucProductlistVi ew
                              {
                              public partial class ucProductlistVi ew : 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<CodeslistC odes;

                              /// <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>Radi us des Kreuzes</summary>
                              int kRad = 5;

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

                              /// <summary>Skalie rung der gesamten Grafik. 1=nicht
                              skaliert.</summary>
                              float gesamtSkalierun g = 1;

                              float fontGrössePunkt Beschreibung = 6.0F;
                              Font punktBeschreibu ngsFont;

                              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.boardNumbe r = boardNumber;
                              }
                              }
                              #endregion

                              Origin _origin = Origin.TopLeft;

                              public ucProductlistVi ew()
                              {
                              InitializeCompo nent();

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

                              punktBeschreibu ngsFont = new Font("Arial",
                              fontGrössePunkt Beschreibung);
                              }

                              private void ListCodesFüllen (ref List<CodeslistC odes, 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(c odes);
                              }
                              }
                              }

                              float zollAlsMillimet er = 25.4F;

                              PointF MillimeterToPix elPointF(Graphi cs g, PointF p)
                              {
                              p.X *= g.DpiX / zollAlsMillimet er;
                              p.Y *= g.DpiY / zollAlsMillimet er;
                              return p;
                              }

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

                              base.OnPaint(e) ;

                              Graphics g = e.Graphics;
                              PointF ptCur;
                              string strPoint;
                              // momentan keine Auswirkung
                              g.ScaleTransfor m(gesamtSkalier ung, gesamtSkalierun g);

                              ptCur = new PointF();
                              foreach (Codes code in listCodes)
                              {
                              ptCur = MillimeterToPix elPointF(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.BoardNumbe r + "(" + code.X + ","
                              + code.Y + ")";
                              //g.DrawString(st rPoint, Font, brush, ptCur.X +
                              xPunktAbstand, ptCur.Y);
                              g.DrawString(st rPoint, punktBeschreibu ngsFont, brush,
                              ptCur.X + xPunktAbstand, ptCur.Y);
                              }



                              float scaleX = (float)panel_dr aw.DisplayRecta ngle.Width /
                              Math.Abs(fWidth );
                              float scaleY = (float)panel_dr aw.DisplayRecta ngle.Height /
                              Math.Abs(fHeigh t);

                              switch (_origin)
                              {
                              case Origin.TopLeft:
                              {
                              Matrix m = new Matrix();
                              m.Translate(0, 0);
                              m.Scale(1, 1);
                              e.Graphics.Tran sform = m;
                              break;
                              }
                              case Origin.TopRight :
                              {
                              Matrix m = new Matrix();
                              m.Translate(fWi dth - 1, 0);
                              //m.Scale(-1, 1);
                              m.Scale(scaleX, scaleY);
                              e.Graphics.Tran sform = m;
                              break;
                              }
                              case Origin.BottomLe ft:
                              {
                              Matrix m = new Matrix();
                              m.Translate(0, fHeight - 1);
                              m.Scale(1, -1);
                              e.Graphics.Tran sform = m;
                              break;
                              }
                              case Origin.BottomRi ght:
                              {
                              Matrix m = new Matrix();
                              m.Translate(fWi dth - 1, fHeight - 1);
                              m.Scale(-1, -1);
                              e.Graphics.Tran sform = m;
                              break;
                              }
                              }

                              }
                              }
                              }


                              Comment

                              Working...