【发布时间】:2014-02-28 12:00:00
【问题描述】:
我想将图形 x,y 坐标 x,y 转换为数学坐标
(在这张图片中,您可以看到图形 x,y 和数学 x,y 之间的差异
e事件得到的图形x和图形y
int graphicalx;
int graphicaly;
graphicalx = e.X;
graphicaly = e.Y;
它们在表单中通过两个标签显示只是应该在表单上移动鼠标
现在将图形 x,y 转换为数学 x,y 的公式是这样的:
图形 x = 数学 x + Alfa
图形 y = - 数学 y + Beta
现在Alfa和Beta通过这个获得:
你得到你的电脑分辨率: 样品矿是: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();
}
Form 1 属性:
窗口状态 = 最大化
FormBorderStyle = 无
【问题讨论】:
-
我不太确定你的意思是数学坐标和图形坐标之间的区别是什么?反对 x 和 y?
-
@einord 看这张照片就明白了:s7.postimg.org/4jejypeor/Untitled.png
标签: c# math graphical-programming