Reputation: 3
I want to draw polyline in WPF. But it shows a point only because difference between points is so small. I have also applied scaleTransform and TranslateTransform but issue remains the same.
Code is
double minX = 25.52524938052284;
double minY = 44.267051317656474;
double maxX = 25.525239580522843;
double maxY = 44.26684671765647;
System.Windows.Point point1 = new System.Windows.Point(minX, minY);
System.Windows.Point point2 = new System.Windows.Point(maxX, maxY);
Polyline myPolyline = new Polyline();
myPolyline.Stroke = System.Windows.Media.Brushes.SaddleBrown;
myPolyline.StrokeThickness = 1;
polylinePointCollection.Add(point1);
polylinePointCollection.Add(point2);
ScaleTransform st = new ScaleTransform(100000,100000,25,25);
myPolyline.RenderTransform = st;
TranslateTransform tt = new TranslateTransform(100, 100);
myPolyline.RenderTransform = tt;
canvas.Children.Add(myPolyline);
This is example code. I have a list of points ranging from 15 - 20 so this small basic difference between co-ordinates must be displayed on the screen but it just shows a point.
Upvotes: 0
Views: 95
Reputation: 2495
You are dealing with some very small differences, and as a result, transformation coordinates are very touchy. Taking your code and making some small adjustments, consider the following:
(Skip the translation and adjusting the numbers very small amount)
double minX = 25.52524938052284;
double minY = 44.267051317656474;
double maxX = 25.525239580522843;
double maxY = 44.26684671765647;
double diffX = maxX - minX; // -0.0000097999999972842033
double diffY = maxY - minY; // -0.00020460000000355194
// setting values to positive small differences
minX = 25.525d;
minY = 44.266d;
maxX = 25.526d;
maxY = 44.267d;
System.Windows.Point point1 = new System.Windows.Point(minX, minY);
System.Windows.Point point2 = new System.Windows.Point(maxX, maxY);
Polyline myPolyline = new Polyline();
myPolyline.Stroke = System.Windows.Media.Brushes.SaddleBrown;
myPolyline.StrokeThickness = 0.0003d; // <-- necessary due to scaling
myPolyline.Points.Add(point1);
myPolyline.Points.Add(point2);
System.Windows.Point center = new System.Windows.Point();
center.X = minX + ((maxX - minX) / 2.0d) - 0.001d;
center.Y = minY + ((maxY - minY) / 2.0d) - 0.001d;
double scale = 100000.0d;
//ScaleTransform st = new ScaleTransform(100000, 100000, 25, 25);
ScaleTransform st = new ScaleTransform(scale, scale, center.X, center.Y);
myPolyline.RenderTransform = st;
//TranslateTransform tt = new TranslateTransform(100, 100);
//myPolyline.RenderTransform = tt;
canvas.Children.Add(myPolyline);
produces this result:
Tolerances for the scale and translation are very sensitive. You may find it easier to magnify the numbers with some coefficient. Note the stroke thickness was adjusted to such a small value. Increasing it slightly will actually make the line look like it is oriented in a different direction.
Hope this helps!
Upvotes: 1