Click here to Skip to main content
12,761,248 members (29,752 online)
Rate this:
Please Sign up or sign in to vote.
See more: WPF
I draw a polygon line with 100 points, the startPoint is (10.000001, 10.000001), the offset = 0.000001, the next point is plus the offset (10.000002, 10.000002), then I zoom the line to 1e6 times or more by matrixTransform, but I saw the the line is not a beeline, is a sawtooth line.
Why does it not work? Do you have any solution for this issue?

I draw the line in a coordinate system (x axis & y axis, like x axis range is the point.x's range, 10.000001~10.0001), and the points are the real data. I want to just draw it by the real points and by the matrixTransform to show the real line I needed.
A strange problem is, I transform the points by matrixTransform, and draw the line is not missing the precision. there is a simple demo for it.

Here is my code:
<Window x:Class="TestMatrix.MainWindow"
        Title="MainWindow" Height="600" Width="700">
    <Grid x:Name="grid">
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="auto"/>

        private List<Point> m_listPoints = new List<Point>();
        private int count = 100;
        private double c_offset = 1e-7;
        private MatrixTransform m_transform;
        public MainWindow()

        private void DrawWithMatrix()
            pathFigure.StartPoint = m_listPoints[0];
            PolyLineSegment poly = new PolyLineSegment(m_listPoints, true);
            polyLineSegment.Points = poly.Points;

            m_transform = new MatrixTransform();
            m_transform.Matrix = GetMatrix(canvas, count);
            geometry.Transform = m_transform;

        private void InitPoints(int count)
            double xValue = 4.989826;
            double yValue = 9.012345;
            for (int i = 0; i < count; i++)
                m_listPoints.Add(new Point(xValue + i * c_offset, yValue + i * c_offset));
        private Matrix GetMatrix(FrameworkElement fe, int count)
            double scaleX = fe.Width / (count * c_offset);
            double scaleY = fe.Height / (count * c_offset);

            Matrix matrix = new Matrix();
            matrix.Translate(-m_listPoints[0].X, -m_listPoints[count - 1].Y);
            matrix.Scale(scaleX, -scaleY);

            return matrix;
        private void DrawNoMatrixTransform()
            var realPoints = GetRealPoints();
            pathFigureNo.StartPoint = realPoints[0];
            PolyLineSegment poly = new PolyLineSegment(realPoints, true);
            polyLineSegmentNo.Points = poly.Points;

        private List<Point> GetRealPoints()
            List<Point> pixelPoints = new List<Point>();
            m_listPoints.ForEach(point =>
                //get realPoint by compute
                //double x = (point.X - m_listPoints[0].X) * noMatrixCanvas.Width / (count * c_offset);
                //double y = -(point.Y - m_listPoints[count - 1].Y) * noMatrixCanvas.Height / (count * c_offset);
                //pixelPoints.Add(new Point(x, y));

                //get realPoint by matrix
                Point realPoint = m_transform.Transform(point);
            return pixelPoints;

Posted 20-Nov-12 5:40am
Updated 21-Nov-12 0:33am
Sergey Alexandrovich Kryukov 20-Nov-12 14:22pm
It is possibly that this is precision, right. The solution is usually possible, but needs a lot more detail. And the solution is very likely lies in the application architecture, not implementation detail. You need to explain your purpose, and the purpose of zoom and other related behaiors...
songwq 21-Nov-12 0:19am
Thank you for your reply. And I add more info, please pay attention to it.
Earloc 21-Nov-12 2:54am
your sample is missing definition of
field "m_transform" and method "GetMatrix"
songwq 21-Nov-12 5:35am
I had updated the code. Thank you for your reminder. :)
songwq 23-Nov-12 23:37pm
Is there any solution for this issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100