Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
I have a half-finished tool for calculating distances between real-life stars, and positions in space, and much more, but I'd like to make a 2D map of the 100'000 closest stars, but I need some advise.

Firstly; making the position X=0 and Y=0 location dead center of the program window, (with two 3px wide lines crossing X=0 Y=0).

Secondly; make a grid-pattern of 1px lines going top-bottom and left-right with a defined space between them, (ex: 24px, which represents one parsec or lightyear).

thirdly; make it scalable, with over 100'000 stars in a database I need to have some kind of zoom capability and a drag capability to view a bigger area, and to maneuver around. Since my DB has distance data for all the stars it wouldn't be difficult to only getting the data for the stars inside a range.

My solution that I have been contemplating is creating a transparent image which would be 15'000 parsecs with the grid pattern, underneath the container it is in have a black background, then overlaying another image witch have small colored gifs on them corresponding to stars and a layer over it again having "tootip-areas" with information about the star when hovering on it, BUT, having worked with images before I just happen to know that even if I had only 5px pr. parsec it would still be 150'000x150'000 image, and having multiple generated would be demanding on any processor, so I'm kinda stuck. My biggest issue is that I have little experience working with graphics as I usually do command-line stuff.

thanks for any advice, links to tutorials, and any other kind of help!

-Frank
Posted
Comments
fjdiewornncalwe 29-Mar-12 13:06pm    
This looks like a very interesting project. I don't have any suggestions for you right away, but I think that this would potentially make a very interesting article. Perhaps you could do that if you feel so inclined.
Frank R. Haugen 29-Mar-12 13:25pm    
If i make it work I'll probably make an article, and also publish the finished program here as it has some nifty features for doing astronomical calculations many people would find useful and amusing.

1 solution

Hello,

If I've taken the point:

1. you need to Convert Point to Cartesian coordinate:

C#
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.
C#
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)
C#
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
 
Share this answer
 
v5
Comments
Frank R. Haugen 30-Mar-12 7:07am    
I like it, however, do you have a solution to make the X,Y's 0,0 become centered in the middle of let's say a canvas?
Shahin Khorshidnia 30-Mar-12 7:49am    
Yes, I said it in Case 1. (you need to Convert Point to Cartesian coordinate)
Frank R. Haugen 30-Mar-12 8:30am    
Ah, now I see, sorry my mind don't work sometimes. Ellipse is BTW a MUCH better approach than images! tnx!
Shahin Khorshidnia 30-Mar-12 8:56am    
You're welcome :)
Frank R. Haugen 30-Mar-12 9:25am    
Some more noobish questions: Couldn't WPF "offset" the X,Y using transforms instead of doing it programatically? (doing it programatically makes it MUCH harder to make it dynamically scalable, as I see it).

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900