Пример #1
0
vector2D eigenVector(const tensor2D& t, const scalar lambda)
{
    if (lambda < SMALL)
    {
        return vector2D::zero;
    }

    if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
    {
        if (lambda > min(t.xx(), t.yy()))
        {
            return vector2D(1, 0);
        }
        else
        {
            return vector2D(0, 1);
        }
    }
    else if (mag(t.xy()) < SMALL)
    {
        return vector2D(lambda - t.yy(), t.yx());
    }
    else
    {
        return vector2D(t.xy(), lambda - t.yy());
    }
}
Пример #2
0
level::level()
{
    WINDOW_SIZEX=800;
    WINDOW_SIZEY=600;
    windowX=0;
    windowY=0;
    font = GLUT_BITMAP_TIMES_ROMAN_24;
    tinyFont = GLUT_BITMAP_8_BY_13;
    enemies_killed = 0;
    enemies_before = 0;
    enemies_after = 0;
    score = 0;
    dtime = 0;
    ftime = 0;
    startingSpeed=(vector2D(0.001,0.005,0,0));
    playerShip = new ship();
    playerShip->set_speed(startingSpeed);
    lifeDraw=playerShip->get_life();
    //paused=true;
    xploded=false;
    highScoreSaved = false;
    MenuChoice=0;
    ZoomLevel=100;
    srand(time(NULL));
}
Пример #3
0
// Return eigenvalues in ascending order of absolute values
vector2D eigenValues(const tensor2D& t)
{
    scalar i = 0;
    scalar ii = 0;

    if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
    {
        i = t.xx();
        ii = t.yy();
    }
    else
    {
        scalar mb = t.xx() + t.yy();
        scalar c = t.xx()*t.yy() - t.xy()*t.yx();

        // If there is a zero root
        if (mag(c) < SMALL)
        {
            i = 0;
            ii = mb;
        }
        else
        {
            scalar disc = sqr(mb) - 4*c;

            if (disc > 0)
            {
                scalar q = sqrt(disc);

                i = 0.5*(mb - q);
                ii = 0.5*(mb + q);
            }
            else
            {
                FatalErrorIn("eigenValues(const tensor2D&)")
                    << "zero and complex eigenvalues in tensor2D: " << t
                    << abort(FatalError);
            }
        }
    }

    // Sort the eigenvalues into ascending order
    if (i > ii)
    {
        Swap(i, ii);
    }

    return vector2D(i, ii);
}
Пример #4
0
void ray_options::set_pos(qreal x, qreal y)
{
	r->set_emitter_pos(vector2D(x, y));
	backgroung->recalc_ray_num(r_num);
	backgroung->update();
}
double orientedAngle(const Point2D & p0, const Point2D & p1, const Point2D & p2) {
    double unsignedAngle = angle(vector2D(p0, p1), vector2D(p0, p2));
    double area = doubleSignedTriangleArea(p0, p1, p2);

    return (area < 0) ? -unsignedAngle: unsignedAngle;
}
Пример #6
0
void Foam::CV2D::newPoints()
{
    const scalar relaxation = relaxationModel_->relaxation();

    Info<< "Relaxation = " << relaxation << endl;

    Field<point2D> dualVertices(number_of_faces());

    label dualVerti = 0;

    // Find the dual point of each tetrahedron and assign it an index.
    for
    (
        Triangulation::Finite_faces_iterator fit = finite_faces_begin();
        fit != finite_faces_end();
        ++fit
    )
    {
        fit->faceIndex() = -1;

        if
        (
            fit->vertex(0)->internalOrBoundaryPoint()
         || fit->vertex(1)->internalOrBoundaryPoint()
         || fit->vertex(2)->internalOrBoundaryPoint()
        )
        {
            fit->faceIndex() = dualVerti;

            dualVertices[dualVerti] = toPoint2D(circumcenter(fit));

            dualVerti++;
        }
    }

    dualVertices.setSize(dualVerti);

    Field<vector2D> displacementAccumulator
    (
        startOfSurfacePointPairs_,
        vector2D::zero
    );

    // Calculate target size and alignment for vertices
    scalarField sizes
    (
        number_of_vertices(),
        meshControls().minCellSize()
    );

    Field<vector2D> alignments
    (
        number_of_vertices(),
        vector2D(1, 0)
    );

    for
    (
        Triangulation::Finite_vertices_iterator vit = finite_vertices_begin();
        vit != finite_vertices_end();
        ++vit
    )
    {
        if (vit->internalOrBoundaryPoint())
        {
            point2D vert = toPoint2D(vit->point());

            // alignment and size determination
            pointIndexHit pHit;
            label hitSurface = -1;

            qSurf_.findSurfaceNearest
            (
                toPoint3D(vert),
                meshControls().span2(),
                pHit,
                hitSurface
            );

            if (pHit.hit())
            {
                vectorField norm(1);
                allGeometry_[hitSurface].getNormal
                (
                    List<pointIndexHit>(1, pHit),
                    norm
                );

                alignments[vit->index()] = toPoint2D(norm[0]);

                sizes[vit->index()] =
                    cellSizeControl_.cellSize
                    (
                        toPoint3D(vit->point())
                    );
            }
        }
    }

    // Info<< "Calculated alignments" << endl;

    scalar cosAlignmentAcceptanceAngle = 0.68;

    // Upper and lower edge length ratios for weight
    scalar u = 1.0;
    scalar l = 0.7;

    PackedBoolList pointToBeRetained(startOfSurfacePointPairs_, true);

    std::list<Point> pointsToInsert;

    for
    (
        Triangulation::Finite_edges_iterator eit = finite_edges_begin();
        eit != finite_edges_end();
        eit++
    )
    {
        Vertex_handle vA = eit->first->vertex(cw(eit->second));
        Vertex_handle vB = eit->first->vertex(ccw(eit->second));

        if (!vA->internalOrBoundaryPoint() || !vB->internalOrBoundaryPoint())
        {
            continue;
        }

        const point2D& dualV1 = dualVertices[eit->first->faceIndex()];
        const point2D& dualV2 =
            dualVertices[eit->first->neighbor(eit->second)->faceIndex()];

        scalar dualEdgeLength = mag(dualV1 - dualV2);

        point2D dVA = toPoint2D(vA->point());
        point2D dVB = toPoint2D(vB->point());

        Field<vector2D> alignmentDirsA(2);

        alignmentDirsA[0] = alignments[vA->index()];
        alignmentDirsA[1] = vector2D
        (
           -alignmentDirsA[0].y(),
            alignmentDirsA[0].x()
        );

        Field<vector2D> alignmentDirsB(2);

        alignmentDirsB[0] = alignments[vB->index()];
        alignmentDirsB[1] = vector2D
        (
           -alignmentDirsB[0].y(),
            alignmentDirsB[0].x()
        );

        Field<vector2D> alignmentDirs(alignmentDirsA);

        forAll(alignmentDirsA, aA)
        {
            const vector2D& a(alignmentDirsA[aA]);

            scalar maxDotProduct = 0.0;

            forAll(alignmentDirsB, aB)
            {
                const vector2D& b(alignmentDirsB[aB]);

                scalar dotProduct = a & b;

                if (mag(dotProduct) > maxDotProduct)
                {
                    maxDotProduct = mag(dotProduct);

                    alignmentDirs[aA] = a + sign(dotProduct)*b;

                    alignmentDirs[aA] /= mag(alignmentDirs[aA]);
                }
            }
        }

        vector2D rAB = dVA - dVB;

        scalar rABMag = mag(rAB);

        forAll(alignmentDirs, aD)
        {
            vector2D& alignmentDir = alignmentDirs[aD];

            if ((rAB & alignmentDir) < 0)
            {
                // swap the direction of the alignment so that has the
                // same sense as rAB
                alignmentDir *= -1;
            }

            scalar alignmentDotProd = ((rAB/rABMag) & alignmentDir);

            if (alignmentDotProd > cosAlignmentAcceptanceAngle)
            {
                scalar targetFaceSize =
                    0.5*(sizes[vA->index()] + sizes[vB->index()]);

                // Test for changing aspect ratio on second alignment (first
                // alignment is neartest surface normal)
                // if (aD == 1)
                // {
                //     targetFaceSize *= 2.0;
                // }

                alignmentDir *= 0.5*targetFaceSize;

                vector2D delta = alignmentDir - 0.5*rAB;

                if (dualEdgeLength < 0.7*targetFaceSize)
                {
                    delta *= 0;
                }
                else if (dualEdgeLength < targetFaceSize)
                {
                    delta *=
                        (
                            dualEdgeLength
                           /(targetFaceSize*(u - l))
                          - 1/((u/l) - 1)
                        );
                }

                if
                (
                    vA->internalPoint()
                 && vB->internalPoint()
                 && rABMag > 1.75*targetFaceSize
                 && dualEdgeLength > 0.05*targetFaceSize
                 && alignmentDotProd > 0.93
                )
                {
                    // Point insertion
                    pointsToInsert.push_back(toPoint(0.5*(dVA + dVB)));
                }
                else if
                (
                    (vA->internalPoint() || vB->internalPoint())
                 && rABMag < 0.65*targetFaceSize
                )
                {
                    // Point removal

                    // Only insert a point at the midpoint of the short edge
                    // if neither attached point has already been identified
                    // to be removed.
                    if
                    (
                        pointToBeRetained[vA->index()] == true
                     && pointToBeRetained[vB->index()] == true
                    )
                    {
                        pointsToInsert.push_back(toPoint(0.5*(dVA + dVB)));
                    }

                    if (vA->internalPoint())
                    {
                        pointToBeRetained[vA->index()] = false;
                    }

                    if (vB->internalPoint())
                    {
                        pointToBeRetained[vB->index()] = false;
                    }
                }
                else
                {
                    if (vA->internalPoint())
                    {
                        displacementAccumulator[vA->index()] += delta;
                    }

                    if (vB->internalPoint())
                    {
                        displacementAccumulator[vB->index()] += -delta;
                    }
                }
            }
        }
    }
Пример #7
0
	inline vector2D operator-(const point2D &p1, const point2D &p2) {
		return vector2D(p1.x - p2.x, p1.y - p2.y);
	}