CG カメラの方位角と仰角による移動計算

目次

C++プログラム

const double PI = 3.14159265358979323846;

void calc(
    const double x1,
    const double y1,
    const double z1,
    const double azimuth,
    const double depression, 
    double *x2, 
    double *y2, 
    double *z2)
{
    const double dist = sqrt(x1*x1 + y1*y1 + z1*z1);
    const double azimuth_rad = atan2(y1, x1) + azimuth * PI/180.0;
    const double depression_rad = atan2(z1, sqrt(x1*x1+y1*y1)) + depression * PI/180.0;
    
    *x2 = dist * cos(azimuth_rad) * cos(depression_rad);
    *y2 = dist * sin(azimuth_rad) * cos(depression_rad);
    *z2 = dist * sin(depression_rad);

    return;
}

参考