绘制地图-如何解释座标 [英] Drawing a map - how to interpret coord

查看:91
本文介绍了绘制地图-如何解释座标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我到底需要什么:
-我想知道如何解释数据(见下文),以便在窗口或图片框等中绘制地图并将图像拖到控件中.我在C#和C ++中使用opengl进行了尝试,最后我遇到了同样的问题,我不知道如何在保留比例的情况下转换/使用数据绘制点和线.


上下文:

我有一个带有表"MapSolarSystems"的MySql数据库.在此表中,我们可以检索太阳能系统"的名称及其坐标X,Y,Z (数据类型: Double ).
每个系统都有一个字段"constellationID",可帮助我们进行分组.通常,一个星座"包含少于10个太阳能系统"

Hi,

What I need exactly :
- I would like to know how I can interpret the data (see below) for drawing a map in a window or picturebox or whatever and being able to drag the image into the control. I tried in C# and in C++ with opengl, at the end I had the same problem, I dont know how to convert/use the data for drawing points and line while conserving proportion.


Context :

I have a MySql database with a table "MapSolarSystems". Into this table, we can retrieve the name of the "solar-system" and his coordinate X,Y,Z (data type: Double).
Each system have a field "constellationID" which help us for grouping. Generally a "constellation" contain less than 10 "solar-systems"

Let me show an example of one row:

int constellationID = 20000001
varchar solarSystemName = FooBar
double    X = -8.85107925999806e+016 
double    Y =  4.23694439668789e+016 
double    Z =  4.45135253464797e+016 
double xMin = -8.85119031484906e+016 
double xMax = -8.85092564717606e+016 
double yMin =  4.23692979274891e+016 
double yMax =  4.23696457492639e+016 
double zMin =  4.45130363558928e+016
double zMax =  4.45141116897829e+016



2D 中绘制星座图后预期的结果如下所示:
插图(图片)


一旦我知道如何处理这些数据,就将使用"Delaunay三角剖分"和"Djikstra" (我已经有了一些opengl示例)之类的算法.


感谢您的阅读,对不起语法.



The result expected after drawing a constellation in 2D look like that :
Illustration (picture)


Once I know how to deal with thoses data, I will use some algorithm like the "Delaunay Triangulation" and "Djikstra" (I got already some opengl samples).


Thanks for reading me, sorry for the grammar.

推荐答案

我认为问题是扩展的问题之一.检查绘图表面(窗口",面板"等)的限制,并缩放最大坐标以使其适合该表面.然后将相同的比例因子应用于所有其他坐标以完成图片.如果图片不成比例,则可能需要添加第二个比例因子,即宽度和高度之间的比例.距离我自己做完这已经有一段时间了,所以我在这里(模糊)的内存中工作.
I think the issue is one of scaling. Check the limits of your drawing surface (Window, panel etc) and scale your largest coordinate such that it fits within that surface. Then apply the same scale factor to all other coordinates to complete your picture. If the picture is then out of proportion you may need to add a second scale factor which is the ratio between width and height. It''s some while since I have done this myself so I''m working from (vague) memory here.


如果,我正确地理解了您的问题正在将double值转换为像素坐标.如果是这种情况,您需要执行以下操作:

OK if I understand correctly your problem is converting the double values to pixel coordinates. If that is the case you need to do something like this:

POINT CoordToPixel(Double X, Double Y)
{
    double XDistance = LargestXVal - SmallestXVal; //Largest distance on the X axis
    double YDistance = LargestYVal - SmallestYVal; //Largest distance on the Y axis
    double LargestDistance = (XDistance >= YDistance) ? XDistance : YDistance; //Choose the larger of the 2 distances
    double Scale =
        ((DisplayAreaXSize <= DisplayAreaYSize ?
        DisplayAreaXSize : DisplayAreaYSize) //Choose the smallest dimension so the whole thing fits in the display area.
        - BORDER_SIZE * 2) / LargestDistance; //BORDER_SIZE is the size of the border you want.
    
    POINT ScreenPosition;

    ScreenPosition.x = (X - GetSmallestXVal()) * Scale + BORDER_SIZE + 0.5;
    ScreenPosition.y = (Y - GetSmallestYVal()) * Scale + BORDER_SIZE + 0.5;

    return ScreenPosition;
}


您将需要弄清楚如何获得边框大小,显示区域的X& Y大小以及最大和最小X& Y值,但这些都不是太大的问题.

别忘了将边框偏移量添加到X和Y坐标.另外,我还为X和Y添加了+ 0.5以便进行四舍五入.


You will need to figure out how to get the border size, display area''s X & Y sizes and the largest and smallest X & Y values but none of those should be too much of a problem.

Don''t forget to add the border offset to the X and Y coordinates. Also I added + 0.5 to X and Y for rounding purposes.


感谢您的帮助.


这篇关于绘制地图-如何解释座标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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