public int test(point a,point b,point c)
{
   //......
}方法如何实现,我感觉我对不起我小学体育老师.C#角度两条直线point

解决方案 »

  1.   

    求出ac的斜率,k1 = (a.y - c.y) / (a.x - c.x)
    ac相对x轴的角度是a1 = arc tan k1
    同理,k2 = (b.y - c.y) / (b.x - c.x)
    a2 = arc tan k2
    角度acb = a1 + a2
      

  2.   

    LZ知道余弦定理不??ABC三点知道了,三边的长度也就知道了如图
    公式
      

  3.   


    static float AngleInDegree(System.Drawing.Point p1, System.Drawing.Point p2, System.Drawing.Point p3)
            {
                System.Drawing.Point p12 = Normalize(Subtract(p1, p2));
                System.Drawing.Point p32 = Normalize(Subtract(p3, p2));
                return (float)(Math.Acos(Dot(p12, p32)) * 180 / Math.PI);
            }        static float Dot(System.Drawing.Point p1, System.Drawing.Point p2)
            {
                return p1.X * p2.X + p1.Y * p2.Y;
            }        static System.Drawing.Point Subtract(System.Drawing.Point p1, System.Drawing.Point p2)
            {
                return new System.Drawing.Point(p1.X - p2.X, p1.Y - p2.Y);
            }        static System.Drawing.Point Normalize(System.Drawing.Point p)
            {
                int length = (int)Math.Sqrt(p.X * p.X + p.Y * p.Y);
                if (length < 10e-6) throw new ArgumentException();
                return new System.Drawing.Point(p.X / length, p.Y / length);
            } class Program
        {
            static void Main(string[] args)
            {
                //调用类库:
                Point a = new Point { x = 0, y = 0};
                Point b = new Point { x = 10, y = 0};
                Point c = new Point { x = 0, y = 10};//2*Math.Sqrt(3) };
                double[] result = Angle.getAllAngle(a, b, c);
                Console.WriteLine(string.Format("a:{0}度, b:{1}度, c:{2}度", result[0], result[1], result[2]));
                Console.Read();
            }
        }
        //类库:
        public struct Point
        {
            public double x;
            public double y;
        }
        public static class Angle
        {
            public static double[] getAllAngle(Point a, Point b, Point c)
            {
                double[] result = new double[3];
                result[0] = getIntersectionAngle(b, c, a);
                result[1] = getIntersectionAngle(a, c, b);
                result[2] = getIntersectionAngle(a, b, c);
                return result;
            }
     
            public static double getIntersectionAngle(Point a, Point b, Point Intersection)
            {
                Point tempPoint1 = new Point { x = Intersection.x - a.x, y = Intersection.y - a.y};
                Point tempPoint2 = new Point { x = Intersection.x - b.x, y = Intersection.y - b.y};
     
                double temp = tempPoint1.x * tempPoint2.x + tempPoint1.y * tempPoint2.y;
                double temp2 = Math.Sqrt(Math.Pow(tempPoint1.x, 2) + Math.Pow(tempPoint1.y, 2));
                double temp3 = Math.Sqrt(Math.Pow(tempPoint2.x, 2) + Math.Pow(tempPoint2.y, 2));
                double tempCos = temp / (temp2 * temp3);
                double result = Math.Acos(tempCos);
     
                return Math.Round(((180 * result) / Math.PI),1);
            }
        }