简体   繁体   中英

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. I've already got x,y to angle and now to complete it i need the z. Here is the code for 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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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