标题:请教大神关于C#直线求夹角的问题。。
取消只看楼主
caijinsong
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-4-28
 问题点数:0 回复次数:0 
请教大神关于C#直线求夹角的问题。。
已知八个点的坐标。。分别依次求出八个点连成的直线的斜率。。通过斜率求直线之间按逆时针方向形成的夹角。。。。代码如下。。:

 double[] X = new double[] {15,24,32,40,39,35,28,16 };
            double[] Y = new double[] {40,35,34,38,50,51,50,53 };
            double[] K = new double[7];
            double[] jiajiao = new double[6];
            int i = 0, j=1;
            double k,max,min,angle,hudu,result;
      
            do
            {
                k = (Y[i+1]-Y[i])/(X[i+1]-X[i]);
                K[i] = k;
                Console.WriteLine("k" + i.ToString() + "={0}", K[i]);
                i++;
            }
            while (i <= 6);
            
            do
            {
                result = ((K[j] - K[j - 1]) / (1 + K[j] * K[j - 1]));
                hudu = Math.Atan(result);
                angle = 180 * (hudu/Math.PI);
                jiajiao[j-1] = angle;
                Console.WriteLine("jiajiao" + j.ToString() + "={0}", jiajiao[j - 1]);
               
                j++;
            }
            while (j <= 6);


运行出来之后直线的斜率是正确的。。但是夹角不对。。。请教一下。。!
搜索更多相关主题的帖子: angle 
2011-05-02 13:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-338585-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.366193 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved