C#Rect类y轴未正确创建

时间:2013-01-18 00:27:57

标签: c# silverlight geometry geocoding

我在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轴被翻转。我已经三次检查输入呼叫的数据是否正确。怎么了?另外我知道我没有提供太多代码,但感觉不再需要了。如果需要,将提供更多。

2 个答案:

答案 0 :(得分: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;

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

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

答案 1 :(得分:0)

Rect geoBounds = new Rect(west, north, (east - west), (north - south));