// Return true if edge is used in opposite order in faces
bool Foam::orientedSurface::consistentEdge
(
    const edge& e,
    const labelledTri& f0,
    const labelledTri& f1
)
{
    return edgeOrder(f0, e) ^ edgeOrder(f1, e);
}
Exemplo n.º 2
0
void Triangles::normaliseC2d()
{
    /////////////////////////////////////////////////////////////////////

    float temp = 0.0;
    float alpha = 0.0;
    float minus_alpha = 0.0; //for clockwise rotations

    float ab = 0.0;
    float ac = 0.0;
    float bc = 0.0;

    fvec AB = fvec(2, 0);
    fvec AC = fvec(2, 0);
    fvec BC = fvec(2, 0);

    f2ten cnew = f2ten(2);
    (cnew[0]).resize(4, 0);
    (cnew[1]).resize(4, 0);

    fvec old = fvec(2, 0);
    ivec edge_order(3, 0);

    /////////////////////////////////////////////////////////////////////

    AB[0] = c2d[0][1] - c2d[0][0];
    AB[1] = c2d[1][1] - c2d[1][0];

    AC[0] = c2d[0][2] - c2d[0][0];
    AC[1] = c2d[1][2] - c2d[1][0];

    BC[0] = c2d[0][2] - c2d[0][1];
    BC[1] = c2d[1][2] - c2d[1][1];

    ab = abs(AB);
    ac = abs(AC);
    bc = abs(BC);

    edge_order = edgeOrder(edge_order, ab, ac, bc);

    cnew = c2d;

    /////////////////////////////////////////////////////////////////////

    //AB is the longest edge, e.g. edge_order[0]=1 !
    if (edge_order[0] == 1)
    {
        //cout << "\nlongest edge: 1, " << flush;
        //AC shortest ?
        if ((edge_order[1] == 2) && (edge_order[2] == 3))
        {
            //cout << "the second is 2\n" << flush;
            //ABC
            c2d[0][3] = 1.0;
            c2d[1][3] = 1.0;
        }
        else if ((edge_order[1] == 3) && (edge_order[2] == 2))
        {
            //cout << "the second is 3\n" << flush;
            //BAC
            c2d = triXflect(c2d, 1, 1);
            c2d[0][3] = 2.0;
            c2d[1][3] = -1.0;
        }
        else
        {
            cout << "\n... unexpected situation occured in" << flush;
            cout << "\nsetting edge order of triangles ...\n" << flush;
        }
    }

    //BC ist the longest edge
    else if (edge_order[0] == 2)
    {
        //cout << "\nlongest edge: 2, " << flush;
        old[0] = 1.0;
        old[1] = 0.0;
        temp = scalar_product(old, BC);
        temp /= bc;
        alpha = acos(temp);
        minus_alpha = (-1) * alpha;

        c2d = triXshift(c2d, c2d[0][1]);

        old[0] = c2d[0][0];
        old[1] = c2d[1][0];
        old = rotate(old, minus_alpha);

        c2d[0][0] = old[0];
        c2d[1][0] = old[0];
        c2d[0][1] = 0.0;
        c2d[1][1] = 0.0;
        c2d[0][2] = bc;
        c2d[1][2] = 0.0;

        //AB shortest ?
        if ((edge_order[1] == 3) && (edge_order[2] == 1))
        {
            //cout << "the second is 3\n" << flush;//BAC
            //BCA
            c2d[0][3] = 2.0;
            c2d[1][3] = 1.0;
        }
        else if ((edge_order[1] == 1) && (edge_order[2] == 3))
        {
            //cout << "the second is 1\n" << flush;//BAC
            //CBA
            c2d = triXflect(c2d, 2, 1);
            c2d[0][3] = 3.0;
            c2d[1][3] = -1.0;
        }
        else
        {
            cout << "\n... unexpected situation occured in" << flush;
            cout << "\nsetting edge order of triangles ...\n" << flush;
        }
    }

    //AC or CA ist the longest edge
    else if (edge_order[0] == 3)
    {
        //cout << "\nlongest edge: 3, " << flush;
        old[0] = 1.0;
        old[1] = 0.0;
        fvec tmp = fvec(2, 0.0);
        tmp[0] = (-1) * AC[0];
        tmp[1] = (-1) * AC[1]; //tmp = CA wanted!!
        temp = scalar_product(tmp, old);
        temp /= ac;
        alpha = acos(temp);

        c2d = triShift(c2d, AC);
        c2d[0][2] = 0.0;
        c2d[1][2] = 0.0;
        c2d[0][0] = ac;
        c2d[1][0] = 0.0;

        old[0] = c2d[0][1];
        old[1] = c2d[1][1];
        old = rotate(old, alpha);
        c2d[0][1] = old[0];
        c2d[1][1] = old[1];

        //BC shortest ?
        if ((edge_order[1] == 1) && (edge_order[2] == 2))
        {
            //cout << "the second is 1\n" << flush;
            //CAB
            c2d[0][3] = 3.0;
            c2d[1][3] = 1.0;
        }
        else if ((edge_order[1] == 2) && (edge_order[2] == 1))
        {
            //cout << "the second is 2\n" << flush;
            //ACB
            c2d = triXflect(c2d, 3, 1);
            c2d[0][3] = 1.0;
            c2d[1][3] = -1.0;
        }
        else
        {
            cout << "\n... unexpected situation occured in" << flush;
            cout << "\nsetting edge order of triangles ...\n" << flush;
        }
    }
    else
    {
        cout << "\n... unexpected situation occured in" << flush;
        cout << "\nsetting edge order of triangles ...\n" << flush;
    }
}