1

グラフィカルな x,y 座標 x,y を数学的座標に変換したい

(この図では、グラフィカルな x,y と数学的な x,y の違いがわかります

状況のスケッチ

e イベントによって取得されるグラフィカル x およびグラフィカル y

         int graphicalx;
        int graphicaly;   
        graphicalx = e.X;
        graphicaly = e.Y;

フォーム内の2つのラベルで示されているのは、フォーム上でマウスを動かすだけです

グラフィックx、yを数学x、yに変換する式は次のとおりです。

グラフィカルな x = 数学的 x + アルファ

グラフィカルな y = -数学的な y + ベータ

これで、アルファとベータは次のように取得されます。

あなたはあなたのコンピュータの解像度を得る: 私のサンプルの場合:1600 * 800

アルファ = 1600 /2 = 800

ベータ = 800/2 = 450

最後に : アルファ = 800 ベータ = 450

そして今、私のプログラムはうまく動作しません。どこに問題がありますか?

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        int graphicalx;
        int graphicaly;
        int mathematicalx;
        int mathematicaly;


        graphicalx = e.X;
        graphicaly = e.Y;


             if (graphicalx > 0)
        {
            graphicalx = graphicalx * -1; //if graphicalX was positive do it negative

        }
        if (graphicaly > 0)
        {
            graphicaly = graphicaly * -1; //if it graphicalY was positive do it negative

            }

        if (graphicalx < 0)
        {
            graphicalx = graphicalx * +1; // if graphicalX was negative do it positive
        }
        if (graphicaly < 0)
        {
            graphicaly = graphicaly * +1; // if graphicalY was negative do it positive
        }


       mathematicalx = graphicalx + 800; // the formula for obtain the mathematical x 
       mathematicaly = graphicaly * -1 + 450; // the formula for obtain the mathematical y 


        label1.Text = "X = " +mathematicalx.ToString();
        label3.Text = "Y = " + mathematicaly.ToString();

    }

フォーム 1 のプロパティ:

Windows の状態 = 最大化

FormBorderStyle = なし

4

2 に答える 2

2

目立つ最初の問題は、逆方程式が実際の逆ではないことです。値を加算するのではなく、減算する必要があります。これを試して:

mathematicalx = graphicalx - 800; // the formula for obtain the mathematical x 
mathematicaly = (graphicaly - 450) * -1; // the formula for obtain the mathematical y 
于 2014-02-28T12:04:27.913 に答える
0

画像と通常の規則に従っていくつかのテスト ケースを作成するには、角と中点が対応関係を満たす必要があります。

graphical     |   mathematical
-------------------------------
 (   0,   0)  |    (-800,  450)
 (   0, 900)  |    (-800, -450)
 (1600,   0)  |    ( 800,  450)
 (1600, 900)  |    ( 800, -450)
 ( 800, 450)  |    (   0,    0)

それはそれを作る

mathematical.x = graphical.x - 800
mathematical.y = 450 - graphical.y
于 2014-02-28T12:39:22.860 に答える