2013-01-18 37 views
0

我正在C#中創建一個Rect,並帶有兩個點。這些點實際上是地理邊界。我遇到的問題是當我創建矩形時y軸被翻轉。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));

所創建的矩形具有以下性質

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軸被翻轉。我已經三重檢查了正在輸入呼叫的數據是否正確。哪裏不對?另外我知道我沒有提供太多的代碼,但不再需要更多的代碼。如果需要,將提供更多。

+0

您使用哪個Point和Rect(在哪個命名空間中)? – Alan

+0

'System.Windows.Rect'和'System.Windows.Point' – Dan

回答

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描述左上角,寬度向右延伸,高度向下延伸。

+0

這有助於理解更多,但我的代碼從該矩形的頂部,左側,右側,底部值繪製爲界限。無論如何手動設置這些值? – Dan

+0

如果您使用C#'Rect'來執行此操作,請不要使用它。你可以創建你自己的類,或者只是反轉座標系的y值來匹配屏幕座標。 – Tawnos

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

這似乎拿出了正確的頂部,但底部現在更大。 – Dan

+0

你試過了:Rect geoBounds = new Rect(new Point(west,south),new Point(east,north)); ? –