本文介绍了请帮我纠正轴方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是根据两个坐标x1和x2获得方向



这里



center = x1;

pointOncircle = x2;





My aim to get direction based on two cordinates x1 and x2

here

center=x1;
pointOncircle=x2;


if (center.X < pointOnCircle.X)
             {
                 UpdateText("right");

             }
             else if (center.X >pointOnCircle.X)
             {

                 UpdateText("left");

             }
             else if (center.Y < pointOnCircle.Y)
             {
                 UpdateText("down");

             }
             else {

                 UpdateText("up");


             }

推荐答案

double angle(Point p1, Point p2)
    {
    double xDiff = p2.X - p1.X;
    double yDiff = p2.Y - p1.Y;
    return Math.Atan2(yDiff, xDiff) * (180 / Math.PI);
    }

然后你需要做的就是查看值:

介于45和-45之间是正确的,依此类推。

Then all you have to do is look at the value:
between 45 and -45 is Right, and so forth.


这篇关于请帮我纠正轴方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:12