日期:2014-05-18  浏览次数:20867 次

用GRAPH画图进行坐标转换后如何取出鼠标所在点的对应坐标
C# code

Grap.TranslateTransform(0, pictureBoxGraph.Height - 1);
                Grap.ScaleTransform(1, -1);

------------------------------- 
            if (IsDrawing && e.Button == MouseButtons.Left && !IsImgMove)
            {
                //将数据点存储以便画线
                _DrawLine.Add(new Point(e.X, e.Y));
            }


虚线下的取的点是实际的点,怎么将它们转换为与坐标系对应的点!

------解决方案--------------------
当A通过几何变换M来得到B。
要把B还原到A,可以用M的矩阵的达到。

这个M,最好预先计算,也可以如例子中用Graphics.Transform来获得。
C# code

{
    Grap.TranslateTransform(0, pictureBoxGraph.Height - 1);
    Grap.ScaleTransform(1, -1);
    this.matrix = Grap.Transform;   // 得到转换矩阵
    this.matrix.Inverse();          // 得到逆转换
}

System.Drawing.Drawing2D.Matrix matrix = new Matrix();
void Form1_MouseDown(object sender, MouseEventArgs e)
{
    Point[] points = {e.Location};
    this.matrix.TransformPoints(points);  //<--
    this.Text = points[0].ToString();
}

------解决方案--------------------
Matrix Transform
看这个,http://nonocast.cn/?p=2835