Hello,
If I've taken the point:
1. you need to Convert
Point
to Cartesian coordinate:
private Point ConvertCartesianToPoint(Point point)
{
double width = this.SkyCanvas.ActualWidth;
double height = this.SkyCanvas.ActualHeight;
double x = point.X;
double y = point.Y;
x += width / 2;
y += height / 2;
y = height - y;
return new Point(x, y);
}
private Point ConvertPointToCartesian(Point point)
{
double width = this.SkyCanvas.ActualWidth;
double height = this.SkyCanvas.ActualHeight;
double x = point.X;
double y = height - point.Y;
x -= width / 2;
y -= height / 2;
return new Point(x, y);
}
2. You need a
Canvas
or a
UniformGrid
or somthing like it for Sky.
WPF Container Controls Overview
3. Use
Ellipse
instead of
Image
for starts.
private void SetStar(Point point, double diameter)
{
Ellipse myStar = new Ellipse()
{
Width = diameter,
Height = diameter,
Stroke = Brushes.LightBlue,
Fill = Brushes.LightBlue
};
SkyCanvas.Children.Add(myStar);
Point realPoint = ConvertCartesianToPoint(point);
Canvas.SetLeft(myStar, realPoint.X);
Canvas.SetTop(myStar, realPoint.Y);
}
Or have more effects, using Blend (Microsoft Expression)
4. Use this to compute the distance between 2 starts (Let's suppose that the stars placed in a 2D page)
Math.Sqrt(Math.Pow((x2 - x1) , 2) + Math.Pow((y2 - y1) , 2))
If you use
UniformGrid
, then you don't need it.
And maybe it's useful for you:
how to make the (0,0) in center inside a Canvas