简体   繁体   中英

c# Calculate a 3D point from starting 3D point using distance and angles

I have this:

    float[] angleTo3Dpoint(double radius, double horizonalAngle, double verticalAngle, float[] center3D)
    {
        float[] edge3D = new float[3];
        double slice = 2 * Math.PI / 360;
        double angle = slice * horizonalAngle;
        edge3D[0] = center3D[0] + radius * Math.Cos(angle);
        edge3D[1] = center3D[1] + radius * Math.Sin(angle);
        edge3D[2] = //some conversion here
        return edge3D;
    }

Question: How to convert an angle(Maybe verticalAngle ) to Z-axis?

The output of edge3D[0] & edge3D[1] works properly, but I don't know how to get Z-axis( edge3D[2] ) converted.

Are you sure the values of edge3D[0] and edge3D[1] are correct? They would be if you had just 2 dimensions, but if you have a 3-dimensional vector of length 'radius' sticking up and to the side at some angle, then the length of its projection onto the surface will be shorter.

First you should calculate the length of the projection of the vector onto the flat surface:

double radius2D = radius * Math.Cos(verticalAngle);

Then you can calculate the horizontal coordinates in a similar way to your code:

edge3D[0] = center3D[0] + radius2D * Math.Cos(horizontalAngle);
edge3D[1] = center3D[1] + radius2D * Math.Sin(horizontalAngle);

And finally calculate the "height" of the vector:

edge3D[2] = center3D[2] + radius * Math.Sin(verticalAngle);

EDIT: in the code above I assume that horizontalAngle and verticalAngle are in radians. If they are in degrees, then you should make a conversion to radians just like you do it in your code.

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