ya2 ya1都是点的坐标,这些都是数学知识,跟程序无关,翻译C#如下: Point a1 = new Point(0, 3); //A线段端点a1 Point a2 = new Point(4, 6); //端点a2 Point b1 = new Point(-1, 1); // 线段端点b1 Point b2 = new Point(-1, 2); //线段端点b2 var A = Math.Atan2(a2.Y - a1.Y, a2.X - a1.X); var B = Math.Atan2(b2.Y - b1.Y, b2.X - b1.X); var C = B - A;
Point a1 = new Point(0, 3); //A线段端点a1
Point a2 = new Point(4, 6); //端点a2
Point b1 = new Point(-1, 1); // 线段端点b1
Point b2 = new Point(-1, 2); //线段端点b2
var A = Math.Atan2(a2.Y - a1.Y, a2.X - a1.X);
var B = Math.Atan2(b2.Y - b1.Y, b2.X - b1.X);
var C = B - A;
angle=acos((A·B)/(|A|*|B|))//转成角度
angle=(180 * System.Math.Acos(angle)) / System.Math.PIvector2(x,y)
线段a的向量: va=va2-va1 va2=(xa2,ya2) va1=(xa1,ya1)
线段b的向量: vb=vb2-vb1 vb2=(xb2,yb2) va1=(xb1,yb1)
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
if (Dotter == 1)
{
dot1.Visible = true;
dot1.Location = e.Location;
Dotter = 2;
}
else if (Dotter == 2)
{
dot2.Visible = true;
dot2.Location = e.Location;
Dotter = 3;
Graphics g = this.pictureBox1.CreateGraphics();
Pen p = new Pen(Color.Black, 2);
g.DrawLine(p, dot1.Location, dot2.Location);
}
else if (Dotter == 3)
{
dot3.Visible = true;
dot3.Location = e.Location;
Dotter = 4; }
else if (Dotter == 4)
{
dot4.Visible = true;
dot4.Location = e.Location;
Dotter = 5;
Graphics g = this.pictureBox1.CreateGraphics();
Pen p = new Pen(Color.Black, 2);
g.DrawLine(p, dot3.Location, dot4.Location);
anglesize.Text = (Angle1(dot1.Location, dot2.Location, dot3.Location,dot4.Location)).ToString() + "°";
}
else if (Dotter==5)
{
dot1.Visible = false;
dot2.Visible = false;
dot3.Visible = false;
dot4.Visible = false;
Dotter = 1;
}
}
private static float Angle1(Point first, Point second, Point third, Point fourth)
{ var A = Math.Atan2(second.Y - first.Y, second.X - first.X);
var B = Math.Atan2(fourth.Y - third.Y, fourth.X - third.X);
return (float)(B - A);
}
这样为什么得不出来角度,只能得到一个零点几的小数点。不知道哪里出了问题
return (float)(B - A);
==>>
return (180 * (float)(B - A)) / Math.PI
return (float)(B - A);
==>>
return (180 * (float)(B - A)) / Math.PI
、多谢!解决了!另外想问下,鼠标点在pictureBox上想出现一个点或者自定义小圈圈怎么做到啊?