I’m creating a geometry of lines and ellipses, now I want to add points to this geometry. I’m creating Ellipses with small radius to do this. But the problem is I’m applying transforms to this geometry. So when I translate and scale, the points get a lot bigger. How do I add points to this geometry such that it doesn’t gets bigger while scaling.
This is how I’m creating the point geometry:
public static Path PointsGeometry(List<Point> Locations, Transform transform)
{
GeometryGroup geometries = new GeometryGroup();
foreach (Point Location in Locations)
{
geometries.Children.Add(new EllipseGeometry
{
Center = Location,
RadiusX = .5,
RadiusY = .5,
}
);
}
geometries.Transform = transform;
Path path = new Path
{
Fill = Brushes.WhiteSmoke,
Data = geometries,
};
return path;
}
>Solution :
In order to draw "dots", you may draw lines with zero length and round stroke caps:
public static Path PointsGeometry(
IEnumerable<Point> locations, Transform transform)
{
var geometries = new GeometryGroup { Transform = transform };
foreach (Point location in locations)
{
geometries.Children.Add(new LineGeometry
{
StartPoint = location,
EndPoint = location
});
}
var path = new Path
{
Stroke = Brushes.WhiteSmoke,
StrokeThickness = 2,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
Data = geometries,
};
return path;
}
Or with a PathGeometry instead of a GeometryGroup:
public static Path PointsGeometry(
IEnumerable<Point> locations, Transform transform)
{
var geometry = new PathGeometry { Transform = transform };
foreach (Point location in locations)
{
var figure = new PathFigure { StartPoint = location };
figure.Segments.Add(new LineSegment(location, true));
geometry.Figures.Add(figure);
}
var path = new Path
{
Stroke = Brushes.WhiteSmoke,
StrokeThickness = 2,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
Data = geometry,
};
return path;
}