0

我在 C# 中用两点创建一个 Rect。这些点实际上是地理界限。我遇到的问题是,当我创建矩形时,y 轴被翻转。

例如说我的数据是west="5.42194487004" south="46.407494" east="17.166386" north="55.056664"

我把它传给Rect geoBounds = new Rect(new Point(west, north),new Point(east, south));

创建的 Rectangle 具有以下属性

    Bottom  55.056664          double
    Height  7.781945           double
    IsEmpty false              bool
    Left    5.864166           double
    Right   15.038887000000003 double
    Top     47.274719          double
    Width   9.1747210000000017 double
    X       5.864166           double
    Y       47.274719          double

Y 轴翻转。我已经三重检查了输入呼叫的数据是否正确。怎么了?我也知道我没有提供太多代码,但觉得不需要更多代码。如果需要,将提供更多。

4

2 回答 2

3

坐标系在屏幕左上角有 0,0,Y 向下增加。Rect.Bottom您可以在该属性的示例页面上看到这一点:http: //msdn.microsoft.com/en-us/library/system.windows.rect.bottom.aspx

请注意该页面上的此评论:

// Bottom property gets the y-axis value of the bottom of the rectangle.  
// For this rectangle the value is 55.
rectInfo = rectInfo + "Bottom: " + myRectangle.Bottom;

和这个:

// Top property gets the y-axis position of the top of the rectangle which is  
// equivalent to getting the rectangle's Y property. 
// For this rectangle the value is 5.
rectInfo = rectInfo + "| Top: " + myRectangle.Top;

显式构造函数进一步支持了这一点:http Rect: //msdn.microsoft.com/en-us/library/ms587929%28v=vs.95%29.aspx

请注意xy描述左上角,其中宽度向右延伸,高度向下延伸。

于 2013-01-18T00:36:08.343 回答
0
Rect geoBounds = new Rect(west, north, (east - west), (north - south));
于 2013-01-18T00:41:11.493 回答