日期:2014-05-18 浏览次数:20822 次
private void button1_Click(object sender, EventArgs e) { string[] strPoint=textBox1.Text.Split(','); double[] dPoint=new double[6]; for(int i=0;i<strPoint.Length;i++) dPoint[i] = double.Parse(strPoint[i]); textBox2.Text = getAngle(dPoint).ToString(); } double getAngle(double[] dPoint) //6个double 依次为x1,y1,x2,y2,x3,y3 { double s1, s2, s3,p,S; s1=Math.Sqrt(Math.Pow(dPoint[0]-dPoint[2],2)+Math.Pow(dPoint[1]-dPoint[3],2)); s2=Math.Sqrt(Math.Pow(dPoint[4]-dPoint[2],2)+Math.Pow(dPoint[5]-dPoint[3],2)); s3=Math.Sqrt(Math.Pow(dPoint[0]-dPoint[4],2)+Math.Pow(dPoint[1]-dPoint[5],2)); p = (s1 + s2 + s3) / 2; S = Math.Sqrt(p * (p - s1) * (p - s2) * (p - s3)); return Math.Round(180*Math.Asin(2 * S / (s1 * s2))/3.14,1);//保留1位小数 }