Examples of Vector2


Examples of mikera.vectorz.Vector2

     * If the eigenvalues are all known, real, and the same this can be used to check them.
     */
    public void testEigenvalues( SymmetricQRAlgorithmDecomposition alg , double expected ) {

        for( int i = 0; i < alg.getNumberOfEigenvalues(); i++ ) {
            Vector2 c = alg.getEigenvalue(i);

            assertTrue(c.y==0);

            assertEquals(expected,c.x,1e-8);
        }
View Full Code Here

Examples of org.bitbucket.kchau.longshot.util.Vector2

 
  public MovableObject()
  {
    /** Default MovableObject has allocated velocity and accel
     * vectors with a position of 0,0.*/
    velocity = new Vector2();
    acceleration = new Vector2();
    this.x = 0;
    this.y = 0;
  }
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

    /**
     * Updates the pressures and densities of all particles in the supplied list.
     * @param particles The particles whose densities and pressures are to be updated.
     */
    private void updatePressureAndDensities(final List<FluidParticle> particles) {
        final Vector2 distance = new Vector2();
        for (int i = particles.size() - 1; i >= 0; --i) {
            final FluidParticle particle = particles.get(i);
            particle.density = 0.0f;
            final List<Integer> neighbours = theGrid.GetNeighbourIndex(particle);
            for (int j = neighbours.size()-1; j>=0; --j  ) {
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

    private void updateForces(final List<FluidParticle> particles, final Vector2 globalForce) {
       
        // Optimise slightly by precomputing a few things needed in our calculations.
        final float halfMass = Constants.PARTICLE_MASS / 2.0f;
        final float massViscosityProduct = Constants.PARTICLE_MASS * theViscosity;
        final Vector2 distance = new Vector2();

        for (int i = particles.size()-1; i >= 0 ; --i) {

            final FluidParticle particle = particles.get(i);

            // Add global force to every particle
            particle.force.add(globalForce);

            // Get neighbours for each of the particles
            final List<Integer> neighbours = theGrid.GetNeighbourIndex(particle);

            for (final int neighbourIndex : neighbours) {

                // Prevent double tests
                if (neighbourIndex > i) {

                    final FluidParticle neighbour = particles.get(neighbourIndex);

                    if (neighbour.density > Constants.FLOAT_EPSILON) {

                        distance.x = particle.position.x - neighbour.position.x;
                        distance.y = particle.position.y - neighbour.position.y;

                        // Pressure
                        float scalar = halfMass * (particle.pressure + neighbour.pressure) / neighbour.density;

                        Vector2 force = theSKPressure.CalculateGradient(distance);
                        force.multiply(scalar);
                        particle.force.subtract(force);
                        neighbour.force.add(force);

                        // Viscosity
                        scalar = massViscosityProduct * theSKViscosity.CalculateLaplacian(distance)
                                 / neighbour.density;

                        force = Vector2.Subtract(neighbour.velocity, particle.velocity);

                        force.multiply(scalar);

                        particle.force.add(force);
                        neighbour.force.subtract(force);      
                    }
                }
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

     */
    private void checkParticleDistance(final List<FluidParticle> particles) {
        final float minDist = 0.5f * theCellSpacing;
        final float minDistSq = minDist * minDist;

        final Vector2 particleSeparation = new Vector2();

        for (int i = particles.size() -1; i >=0; --i) {

            final FluidParticle particle = particles.get(i);

            final List<Integer> neighbours = theGrid.GetNeighbourIndex(particle);

            for (int j=neighbours.size()-1; j>=0; --j) {
                final int neighbourIndex = neighbours.get(j);
                // Prevent double tests
                if (neighbourIndex > i) {
                    final FluidParticle neighbour = particles.get(neighbourIndex);
                    particleSeparation.x = neighbour.position.x - particle.position.x;
                    particleSeparation.y = neighbour.position.y - particle.position.y;
                    final float particleSeparationSquared = particleSeparation.getLengthSqaured();
                    if (particleSeparationSquared < minDistSq) {
                        if (particleSeparationSquared > Constants.FLOAT_EPSILON) {
                            final float distLen = particleSeparation.getLength();
                            particleSeparation.multiply(0.5f * (distLen - minDist) / distLen);
                            neighbour.position.subtract(particleSeparation);
                            neighbour.oldPosition.subtract(particleSeparation);
                            particle.position.add(particleSeparation);
                            particle.oldPosition.add(particleSeparation);
                        }
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

        final int particlesToEmit = Constants.NUMBER_OF_PARTICLES;

        for (int i = 0; i < particlesToEmit; ++i) {

            final Vector2 particleVelocity = getEmittedParticleVelocity();

            final Vector2 particlePosition = new Vector2(thePosition.x, thePosition.y);

            // Calc Oldpos (for right velocity) using simple euler
            // oldPos = this.Position - vel * m_time;
            Vector2 oldParticlePosition = Vector2.Mult(particleVelocity, (float) theTimeSinceLastEmission);
            oldParticlePosition = Vector2.Subtract(thePosition, oldParticlePosition);

            particles.add(new FluidParticle(particlePosition,
                                            oldParticlePosition,
                                            particleVelocity,
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

        return particles;
    }

    private Vector2 getEmittedParticleVelocity() {
        float dist = (float) RAND.nextDouble() * theDistribution - theDistribution * 0.5f;
        Vector2 normal = theDirection.PerpendicularRight();
        normal = Vector2.Mult(normal, dist);
        Vector2 particleVelocity = Vector2.Add(theDirection, normal);
        particleVelocity.normalize();
        float velLen = (float) RAND.nextDouble() * (theMaxVelocity - theMinVelocity) + theMinVelocity;
        particleVelocity.multiply(velLen);
        return particleVelocity;
    }
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

     */
    public FluidParticle(final Vector2 position, final Vector2 oldPosition, final Vector2 velocity, final float mass) {
        this.mass = mass;
        this.position = position;
        this.oldPosition = oldPosition;
        this.force = new Vector2();
        this.velocity = velocity;
        this.density = Constants.DENSITY_OFFSET;
        theSolver = new VerletSolver(0.01f);
        updatePressure();
    }
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

   * @param mass The mass of the particle
   * @param timeStep The time (in seconds) over which the position etc has changed
   */
  public void solve(final Vector2 position, final Vector2 positionOld, final Vector2 velocity, final Vector2 force, final float mass, final float timeStep)
    {
    final Vector2 acceleration = Vector2.Divide(force, mass)
        this.solve(position, positionOld, velocity, acceleration, timeStep);
    }
View Full Code Here

Examples of org.cmj.flowy.simulation.math.Vector2

      float origPosY = position.y;
     
      // Position = Position + (1.0f - Damping) * (Position - PositionOld) +
    // dt * dt * a;
    acceleration.multiply(timeStep * timeStep);
    Vector2 temp = Vector2.Subtract(position, positionOld);
    temp.multiply(1.0f - theDamping);
    temp.add(acceleration);
    position.add(temp);
    positionOld.x = origPosX;
    positionOld.y = origPosY;
   
    // calculate velocity
    // Velocity = (Position - PositionOld) / dt;
    temp = Vector2.Subtract(position, positionOld);
    temp.divide(timeStep);
    velocity.setFromVector(temp);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.