introlab / odas

ODAS: Open embeddeD Audition System
MIT License
779 stars 247 forks source link

How to calculate octagon points in fine resolutions grids? #254

Open mycool666 opened 2 years ago

mycool666 commented 2 years ago

Hi, I don't understand the principle of calculating octagon points in fine resolutions grids.Can you tell me where this computing idea comes from or some documents that I can refer to?Here is a code snippet:

    ux = points->array[index*3+0];
    uy = points->array[index*3+1];
    uz = points->array[index*3+2];

    x1 = points->array[iPointMin*3+0];
    y1 = points->array[iPointMin*3+1];
    z1 = points->array[iPointMin*3+2];

    dot = (ux*x1) + (uy*y1) + (uz*z1);

    x0 = ux + x1 - dot * ux;
    y0 = uy + y1 - dot * uy;
    z0 = uz + z1 - dot * uz;

    /*
    tx = ux - x0;
    ty = uy - y0;
    tz = uz - z0;

    tx *= 0.75f;
    ty *= 0.75f;
    tz *= 0.75f;

    x0 = ux - tx;
    y0 = uy - ty;
    z0 = uz - tz;
    */

    nAngles = 8;

    points_octo = points_construct_zero(nAngles);

    for (iAngle = 0; iAngle < nAngles; iAngle++) {

        theta = 2*M_PI * ((float) iAngle) / ((float) nAngles);

        R11 = cosf(theta) + (ux*ux) * (1.0f - cosf(theta));
        R12 = (ux*uy) * (1.0f - cosf(theta)) - uz * sinf(theta);
        R13 = (ux*uz) * (1.0f - cosf(theta)) + uy * sinf(theta);
        R21 = (uy*ux) * (1.0f - cosf(theta)) + uz * sinf(theta);
        R22 = cosf(theta) + (uy*uy) * (1.0f - cosf(theta));
        R23 = (uy*uz) * (1.0f - cosf(theta)) - ux * sinf(theta);
        R31 = (uz*ux) * (1.0f - cosf(theta)) - uy * sinf(theta);
        R32 = (uz*uy) * (1.0f - cosf(theta)) + ux * sinf(theta);
        R33 = cosf(theta) + (uz*uz) * (1.0f - cosf(theta));

        xR = R11 * x0 + R12 * y0 + R13 * z0;
        yR = R21 * x0 + R22 * y0 + R23 * z0;
        zR = R31 * x0 + R32 * y0 + R33 * z0;

        norm = sqrtf(xR*xR + yR*yR + zR*zR);

        xR /= norm;
        yR /= norm;
        zR /= norm;

        points_octo->array[iAngle*3+0] = xR;
        points_octo->array[iAngle*3+1] = yR;
        points_octo->array[iAngle*3+2] = zR;

    }

Many thanks! Best regards, mycool666