12,761,248 members (29,752 online)

Email

Password

Sign in with

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?

MoreInfo:

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:

Xaml:

CS:

Thanks

Weiqiang

Why does it not work? Do you have any solution for this issue?

MoreInfo:

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:

Xaml:

```
<Window x:Class="TestMatrix.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="700">
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
```

CS:

```
private List<Point> m_listPoints = new List<Point>();
private int count = 100;
private double c_offset = 1e-7;
private MatrixTransform m_transform;
public MainWindow()
{
InitializeComponent();
InitPoints(count);
DrawWithMatrix();
DrawNoMatrixTransform();
}
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);
pixelPoints.Add(realPoint);
}
);
return pixelPoints;
}
```

Thanks

Weiqiang

Comments

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

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

--SA

field "m_transform" and method "GetMatrix"