需要有关如何在C#/WPF中制作动态星图的一些建议 [英] Need some suggestions on how to make a dynamic starmap in C#/WPF

查看:126
本文介绍了需要有关如何在C#/WPF中制作动态星图的一些建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个半成品工具,可以计算现实生活中的恒星之间的距离,空间位置等等,但是我想制作100'000个最接近恒星的2D地图,但是我需要一些建议.

首先;使得位置X = 0和Y = 0位置位于程序窗口的死点,(两条3px宽的线与X = 0 Y = 0交叉).

第二;制作一个从上到下,从左到右的1px线的网格模式,它们之间具有定义的间隔(例如:24px,代表一秒差距或光年).

第三;要使其具有可伸缩性,并且数据库中有超过100'000星,我需要具有某种缩放功能和拖动功能,以查看更大的区域并进行机动.由于我的数据库具有所有恒星的距离数据,因此仅获取范围内恒星的数据将很容易.

我一直在考虑的解决方案是创建一个透明的图像,该图像将具有15''000秒差距的网格图案,在其下方的容器中具有黑色背景,然后覆盖另一个图像,在其上具有与星星相对应的彩色gif图像并且在它上面的图层上又有一个太尖区域",上面有关于恒星的信息,但是,在我碰巧知道即使我只有5px的像素之前,我已经使用过图像.差距仍然是150"000x150" 000图像,并且在任何处理器上都需要生成多个图像,所以我有点卡住了.我最大的问题是,我通常不使用命令行,因此对图形的处理经验很少.

感谢您的任何建议,教程链接以及任何其他形式的帮助!

-Frank

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

推荐答案

您好,

如果我明白了这一点:

1.您需要将Point转换为笛卡尔坐标:

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.对于Sky,您需要CanvasUniformGrid或类似的东西.
WPF容器控件概述

3.使用Ellipse代替Image作为开始.



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);
}



或使用Blend(Microsoft Expression)产生更多效果

4.使用它来计算2个起点之间的距离(让我们假设将星星放置在2D页面中)



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))


如果使用UniformGrid,则不需要它.

也许对您有用:
如何制作(0,0 )放在画布的中央


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


这篇关于需要有关如何在C#/WPF中制作动态星图的一些建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆