简体   繁体   English

如何在C#中将z坐标转换为角度?

[英]How to convert z coordinate to an angle in c#?


I've been searching the net for hours to convert z-axis coordinate to an angle. 我一直在网上搜索数小时,以将z轴坐标转换为角度。 I've already got x,y to angle and now to complete it i need the z. 我已经有了x,y的角度,现在要完成它,我需要z。 Here is the code for x,y: 这是x,y的代码:

        private float XYToDegrees(Point xy, Point origin)
    {
        int deltaX = origin.X - xy.X;
        int deltaY = origin.Y - xy.Y;

        double radAngle = Math.Atan2(deltaY, deltaX);
        double degreeAngle = radAngle * 180.0 / Math.PI;

        return (float)(180.0 - degreeAngle);
    }

and this code to run the function: 并使用以下代码运行该功能:

XYToDegrees(new Point(2334, -447), new Point(2433, -659)) - 270;

The purpose of the z coordinate to angle is to get the camera angle aligned with the object I'm looking at. z坐标与角度的目的是使相机角度与我正在查看的对象对齐。

It is very simmilar, just another triangle 非常相似,只是另一个三角形

private float XYZToDegrees(double deltaX, double deltaY, double deltaZ)
{
    double deltaXY = Math.Sqrt(deltaY * deltaY + deltaX * deltaX);
    double radAngle = Math.Atan2(deltaZ, deltaXY);
    double degreeAngle = radAngle * 180.0 / Math.PI;

    return (float)degreeAngle;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM