Package javax.vecmath

Examples of javax.vecmath.Vector2d


     * Advect a single water particle.
     * @return  the magnitude of its velocity vector.
     */
    private double advectWaterParticle(double timeStep, Particle particle, int i, int j) {

        Vector2d vel = interpolator.findVelocity(particle);

        // scale the velocity by the cell size so we can assume the cells have unit dims
        vel.scale(CellDimensions.INVERSE_CELL_SIZE);

        double xChange = timeStep * vel.x;
        double yChange = timeStep * vel.y;
        particle.set( particle.x + xChange, particle.y + yChange );
        particle.incAge( timeStep );

        Cell newHomeCell = findNewHomeCell(particle, i, j);

        assert ( particle.x >= 1 && particle.y >= 1
                && particle.x < grid.getXDimension() - 1
                && particle.y < grid.getYDimension() - 1) :
                "particle.x=" + particle.x + "particle.y=" + particle.y ;

        // adjust # particles as they cross cell boundaries
        newHomeCell.incParticles(); // increment new cell
        grid.getCell(i, j).decParticles()// decrement last cell
        particle.setCell( newHomeCell );

        assert ( grid.getCell(i, j).getNumParticles() >= 0):
                "The number of particles in grid[" + i + "][" + j + "] is " + grid.getCell(i, j).getNumParticles();
        assert ( newHomeCell.getNumParticles() >= 0 );
        return vel.length();
    }
View Full Code Here


            for (int i = 1; i < xDim-1; i++ ) {
                double xDiff = centerX-i;
                double yDiff = centerY-j;

                double theta = Math.atan2(yDiff, xDiff);
                Vector2d tangentialVec = new Vector2d(-Math.sin(theta), Math.cos(theta));

                setVelocity(i, j, tangentialVec);
                getCell(i, j).setStatus(status);
            }
        }
View Full Code Here

            for (int i = 1; i < xDim-1; i++ ) {
                double xDiff = centerX-i;
                double yDiff = centerY-j;
                double dist = Math.sqrt(xDiff*xDiff + yDiff*yDiff);
                double scale = (maxDist - dist)/maxDist;
                Vector2d vel = new Vector2d(velocity.x*scale, velocity.y*scale);
                setVelocity(i, j, vel);
                this.getCell(i, j).setStatus(status);
            }
        }
    }
View Full Code Here

         String vecString = DomUtil.getAttribute(n, vecAttribute);
         int commaPos = vecString.indexOf(",");
         assert commaPos != -1;
         double x = Double.parseDouble(vecString.substring(0, commaPos));
         double y = Double.parseDouble(vecString.substring(commaPos + 1));
         return new Vector2d(x, y);
    }
View Full Code Here

        }
    }

    private void addSource(Source source) {
        //add a spigot of liquid
        Vector2d velocity = source.getVelocity();

        if (source.isOn(time)) {
            for (int i = source.getStart().getX(); i <= source.getStop().getX(); i++ ) {
                 for (int j = source.getStart().getY(); j <= source.getStop().getY(); j++ ) {
                     grid.setVelocity(i, j, velocity);
View Full Code Here

        VelocityInterpolator interpolator = new VelocityInterpolator(grid);
        double maxY = getMaxY();

        for (Particle p : env_.getParticles()) {
            if (options.getShowVelocities()) {
                Vector2d vel = interpolator.findVelocity(p);
                p.get(a_);
                double x = (scale_ * a_[0]) + OFFSET;

                double xLen = x + VELOCITY_SCALE * vel.x;
                double y = maxY - scale_ * a_[1];
 
View Full Code Here

     */
    public void updateVelocity( double timeStep, double gravity ) {

        Logger.log( 1, "stepForward: about to update the velocity field (timeStep=" + timeStep + ')' );
        int i, j;
        Vector2d force = new Vector2d(0, gravity);
        VelocityUpdater velocityUpdater = new VelocityUpdater();

        for ( j = 1; j < grid.getYDimension() - 1; j++ ) {
            for ( i = 1; i < grid.getYDimension() - 1; i++ ) {
                velocityUpdater.updateTildeVelocities(grid.getCell(i, j), grid.getNeighbors(i,j),
View Full Code Here

        g2.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                useAntialiasing_ ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF );

        Point2d newCenter = snake_.getCenter();
        Vector2d distanceDelta = new Vector2d( oldCenter_.x - newCenter.x, oldCenter_.y - newCenter.y );
        velocity_ = distanceDelta.length() / (getNumStepsPerFrame() * timeStep_);
        distance_.add( distanceDelta );

        BackgroundGridRenderer bgRenderer = new BackgroundGridRenderer(gridColor_);
        bgRenderer.drawGridBackground(g2, CELL_SIZE, XDIM, YDIM, distance_);

View Full Code Here

     * Construct the particle
     * assumes that the initial velocity is 0.
     */
    public Particle( double x, double y, double m ) {
        super( x, y );
        velocity = new Vector2d( 0.0, 0.0);
        acceleration = new Vector2d( 0.0, 0.0 );
        force = new Vector2d( 0.0, 0.0 );
        frictionalForce = new Vector2d( 0.0, 0.0 );
        mass = m;
    }
View Full Code Here

     */
    public void updateForces(Segment segment) {
        Edge[] edges_ = segment.getEdges();
        Particle[] particles_ = segment.getParticles();

        Vector2d e0Force = edges_[0].getForce();
        Vector2d e1Force = edges_[1].getForce();
        Vector2d e2Force = edges_[2].getForce();
        Vector2d e4Force = edges_[4].getForce();
        Vector2d e5Force = edges_[5].getForce();
        Vector2d e6Force = edges_[6].getForce();
        Vector2d e7Force = edges_[7].getForce();

        // update the front 3 particle forces
        particles_[1].force.set( 0, 0 );
        particles_[1].force.add( e0Force );
        particles_[1].force.sub( e5Force );
        particles_[1].force.sub( e1Force );

        particles_[2].force.set( 0, 0 );
        particles_[2].force.sub( e2Force );
        particles_[2].force.sub( e6Force );
        particles_[2].force.add( e1Force );

        particles_[CENTER_INDEX].force.set( 0, 0 );
        particles_[CENTER_INDEX].force.add( e4Force );
        particles_[CENTER_INDEX].force.add( e7Force );
        particles_[CENTER_INDEX].force.add( e5Force );
        particles_[CENTER_INDEX].force.add( e6Force );

        if ( !segment.isHead() ) {
            Segment segmentInFront = segment.segmentInFront_;
            particles_[1].force.sub(segmentInFront.getRightForce());
            particles_[1].force.sub(segmentInFront.getRightBackDiagForce());

            particles_[2].force.add( segmentInFront.getLeftForce() );
            particles_[2].force.sub(segmentInFront.getLeftBackDiagForce());
        }
        if (segment.isTail()) {
            Vector2d e3Force = edges_[3].getForce();

            // update back 2 particle forces if at tail
            particles_[0].force.set( 0, 0 );
            particles_[0].force.sub( e3Force );
            particles_[0].force.sub( e0Force );
View Full Code Here

TOP

Related Classes of javax.vecmath.Vector2d

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.