Package javax.vecmath

Examples of javax.vecmath.Vector2d


            RoboterConstruction roboterConstruction = roboterController.getRoboterConstruction();
            for (LightBulbController lightBulbController : lightBulbControllers) {

              // Left Light Sensor
              Point2d leftLightSensorPoint = roboterConstruction.getRoboterElementPoint(roboter.getLeftLightSensor());
              Vector2d leftLightSensorVector = roboterConstruction.getRoboterElementAngleVector(roboter.getLeftLightSensor());

              leftSensorIntensity = leftSensorIntensity
                  + lightBulbController.calculateIntensity(leftLightSensorPoint, roboter.getLeftLightSensor(),
                      leftLightSensorVector);

              // Right Light Sensor
              Point2d rightLightSensorPoint = roboterConstruction.getRoboterElementPoint(roboter.getRightLightSensor());
              Vector2d rightLightSensorVector = roboterConstruction.getRoboterElementAngleVector(roboter
                  .getRightLightSensor());

              rightSensorIntensity = rightSensorIntensity
                  + lightBulbController.calculateIntensity(rightLightSensorPoint, roboter.getRightLightSensor(),
                      rightLightSensorVector);
View Full Code Here


    double sideX = line.sideX;
    double sideY = line.sideY;
    double sideVectX = line.sideVectX;
    double sideVectY = line.sideVectY;

    Vector2d direction = rm.getNewDirectionVector();
    direction.normalize();
    RealMatrix coefficients = new Array2DRowRealMatrix(new double[][] { { direction.getX(), -(sideVectX) },
        { direction.getY(), -(sideVectY) } }, false);
    DecompositionSolver solver = new LUDecompositionImpl(coefficients).getSolver();
    RealVector constants = new ArrayRealVector(new double[] { sideX - roboter1.getX(), sideY - roboter1.getY() }, false);
    RealVector solution = solver.solve(constants);

    double r = solution.getEntry(0);
    // double s = solution.getEntry(1);

    double res1 = roboter1.getX() + direction.getX() * r;
    double res2 = roboter1.getY() + direction.getY() * r;

    Point2d p = new Point2d(res1, res2);
    return p;
  }
View Full Code Here

        // TODO: Gravity detection
        for (int i = 0; i < fWorld.objects.size(); i++) {
          FysixObject fo1 = (FysixObject) fWorld.objects.get(i);                          
          for (int j = i+1; j < fWorld.objects.size(); j++) {
              FysixObject fo2 = (FysixObject) fWorld.objects.get(j);
              Vector2d dist = new Vector2d(0,0);
              dist.sub(fo2.getPosition(), fo1.getPosition());
              int len = (int)dist.length();
              if(len>0 && len < 250){ // Affect area...
                //Vector2d alfa = new Vector2d(fo1.getPosition());
                FysixObject foA;
                FysixObject foB;
                if(fo1.getMass() <= fo2.getMass()){
                  foA = fo1;
                  foB = fo2;
                } else {
                  foA = fo2;
                  foB = fo1;                 
                }
             
                double A = Math.abs(foB.getPosition().y-foA.getPosition().y);
                double B = Math.abs(foB.getPosition().x-foA.getPosition().x);
                double a = Math.atan(A/B);                
               
                if(foA.getPosition().x >= foB.getPosition().x &&
                      foA.getPosition().y >= foB.getPosition().y )
                   {
                     a = Math.PI - a;
                   }
                else if(foA.getPosition().x >= foB.getPosition().x &&
                      foA.getPosition().y <= foB.getPosition().y )
                   {
                     a = Math.PI + a;
                   }
                else if(foA.getPosition().x <= foB.getPosition().x &&
                      foA.getPosition().y <= foB.getPosition().y )
                   {
                     a = 2*Math.PI - a;
                   }
               
                double G = 0.0000006;
                double gravForce = G*foA.getMass()*foB.getMass()/len*len;
               
                Vector2d gravAcc = new Vector2d(gravForce*Math.cos(-a), -gravForce*Math.sin(a));              
                  Vector2d gravVelocity = new Vector2d(0,0);
                 
                  // v = v0 + a * dt
                  gravAcc.scale(deltaTime / 1000.0);
                  gravVelocity.add(foA.getVelocity());
                  gravVelocity.add(gravAcc);
                  foA.setVelocity(gravVelocity);
              }
          }
        }
       
        for (Iterator i = fWorld.getAllObjects(); i.hasNext(); ) {
            FysixObject fo = (FysixObject) i.next();
            Vector2d totAcc = env.getEnvironmentAccelerationAtPoint(fo.getPosition());
            Vector2d newVelocity = new Vector2d(0,0);
           
            // v = v0 + a * dt
            totAcc.add(fo.getAcceleration());
            totAcc.scale(deltaTime / 1000.0);
            newVelocity.add(fo.getVelocity());
            newVelocity.add(totAcc);
            newVelocity.scale(env.getEnvironmentalResistanceAtPoint(fo.getPosition()));
            fo.setVelocity(newVelocity);
        }
       
        // TODO: Collision detection
        for (int i = 0; i < fWorld.objects.size(); i++) {
          FysixObject fo1 = (FysixObject) fWorld.objects.get(i);
          for (int j = i+1; j < fWorld.objects.size(); j++) {
              FysixObject fo2 = (FysixObject) fWorld.objects.get(j);
            if (FysixCollisionDetector.checkCollision(fo1, fo2)) {
                  // TODO: Elastic collision detection
              // vn1 = 2*m2*vo2+vo1*(m1-m2) / (m2+m1)
              // vn2 = 2*m1*vo1+vo2*(m2-m1) / (m1+m2)
              /*
              fo1.getVelocity().x = 2*fo2.getMass()*fo2.getVelocity().x+fo1.getVelocity().x*(fo1.getMass()-fo2.getMass())/(fo1.getMass()+fo2.getMass());
              fo1.getVelocity().y = 2*fo2.getMass()*fo2.getVelocity().y+fo1.getVelocity().y*(fo1.getMass()-fo2.getMass())/(fo1.getMass()+fo2.getMass());
             
              fo2.getVelocity().x = 2*fo1.getMass()*fo1.getVelocity().x+fo2.getVelocity().x*(fo2.getMass()-fo1.getMass())/(fo1.getMass()+fo2.getMass());
              fo2.getVelocity().y = 2*fo1.getMass()*fo1.getVelocity().y+fo2.getVelocity().y*(fo2.getMass()-fo1.getMass())/(fo1.getMass()+fo2.getMass());
              */
              fo1.color = Color.RED;
              fo2.color = Color.RED;
            } else {
              fo1.color = Color.GREEN;
              fo2.color = Color.GREEN;
            }
          }
        }              
       
        for (Iterator i = fWorld.getAllObjects(); i.hasNext(); ) {
            FysixObject fo = (FysixObject) i.next();
            Vector2d move;
           
            // s = v * dt
            move = (Vector2d) fo.getVelocity().clone();
            move.scale(deltaTime / 1000.0);
            fo.getPosition().add(move);
            fWorld.updateObject(fo);
        }
    }
View Full Code Here

    public void setDirection(double angle) {
      Matrix3d mat = new Matrix3d();
      mat.rotZ(angle);
      Vector3d tmp = new Vector3d(1, 0, 0);
      mat.transform(tmp);
      direction = new Vector2d(tmp.x, tmp.y);
    }
View Full Code Here

    double max;
  }

  private static ProjectionResult ProjectPolygon(Vector2d axis, Polygon polygon) {
    ProjectionResult res = new ProjectionResult();
    Vector2d projVec = new Vector2d(polygon.xpoints[0], polygon.ypoints[0]);
    double dotProduct = axis.dot(projVec);
    res.max = dotProduct;
    res.min = dotProduct;

    for (int i = 0; i < polygon.npoints; i++) {
View Full Code Here

      int edgeCountA = polygonA.npoints;
      int edgeCountB = polygonB.npoints;
      //double minIntervalDistance = Double.MAX_VALUE;
      //Vector2d translationAxis = new Vector2d();
      Vector2d edge = new Vector2d();

      // Loop through all the edges of both polygons
      for (int edgeIndex = 1; edgeIndex <= edgeCountA + edgeCountB; edgeIndex++) {
          if (edgeIndex <= edgeCountA) {
          int wrapIdx = edgeIndex % edgeCountA;
              edge.x = polygonA.xpoints[wrapIdx] - polygonA.xpoints[edgeIndex-1];
              edge.y = polygonA.ypoints[wrapIdx] - polygonA.ypoints[edgeIndex-1];
          } else {
          int wrapIdx = (edgeIndex - edgeCountA) % edgeCountB;
              edge.x = polygonB.xpoints[wrapIdx] - polygonB.xpoints[edgeIndex - edgeCountA - 1];
              edge.y = polygonB.ypoints[wrapIdx] - polygonB.ypoints[edgeIndex - edgeCountA - 1];
          }

          // ===== 1. Find if the polygons are currently intersecting =====

          // Find the axis perpendicular to the current edge
          Vector2d axis = new Vector2d(-edge.y, edge.x);
          axis.normalize();

          // Find the projection of the polygon on the current axis
          //float minA = 0; float minB = 0; float maxA = 0; float maxB = 0;
          ProjectionResult resA = ProjectPolygon(axis, polygonA);
          ProjectionResult resB = ProjectPolygon(axis, polygonB);

          // Check if the polygon projections are currentlty intersecting
          if (IntervalDistance(resA, resB) > 0)
              result.doesIntersect = false;

          // ===== 2. Now find if the polygons *will* intersect =====

          // Project the velocity on the current axis
          double velocityProjection = axis.dot(velocity);

          // Get the projection of polygon A during the movement
          if (velocityProjection < 0) {
              resA.min += velocityProjection;
          } else {
View Full Code Here

   * {@inheritDoc}
   */
  public KinematicBehaviourOutput runWander(Point2d position, Vector2d orientation, double linearSpeed, double maxLinearSpeed, double angularSpeed, double maxAngularSpeed) {
    KinematicBehaviourOutput output = new KinematicBehaviourOutput();
   
    Vector2d v = new Vector2d(orientation);
    if (v.length()>0) v.normalize();
    v.scale(maxLinearSpeed);
   
    output.setLinear(v.x, v.y);
   
    output.setAngular((Math.random() - Math.random()) * maxAngularSpeed);
   
 
View Full Code Here

  }

  @Override
  public Status live() {
    Point2d position = new Point2d(getX(), getY());
    Vector2d orientation = getDirection();
    double linearSpeed = getCurrentLinearSpeed();
    double angularSpeed = getCurrentAngularSpeed();
   
    BehaviourOutput output = null;
View Full Code Here

 
  /**
   * {@inheritDoc}
   */
  public SteeringBehaviourOutput runWander(Point2d position, Vector2d orientation, double linearSpeed, double maxLinearAcc, double angularSpeed, double maxAngularAcc) {
    Vector2d circleDirection = new Vector2d(orientation);
    circleDirection.scale(this.circleDistance);
   
    Point2d circleCenter = new Point2d();
    circleCenter.add(position, circleDirection);

    double deltaAngle = (Math.random() - Math.random()) * this.maxRotation;
    this.rotation = GeometryUtil.clamp(this.rotation+deltaAngle, -Math.PI, Math.PI);
   
    Vector2d targetDirection = new Vector2d(orientation);
    targetDirection.normalize();
    targetDirection.scale(this.circleRadius);
    GeometryUtil.turnVector(targetDirection, this.rotation);
   
    Point2d faceTarget = new Point2d();
    faceTarget.add(circleCenter, targetDirection);
       
    SteeringBehaviourOutput output = this.faceBehaviour.runFace(position, orientation, angularSpeed, maxAngularAcc, faceTarget);
   
    if (output==null) output = new SteeringBehaviourOutput();
   
    targetDirection = new Vector2d(orientation);
    targetDirection.normalize();
    targetDirection.scale(maxLinearAcc);
   
    output.setLinear(targetDirection.x, targetDirection.y);
   
    return output;
  }
View Full Code Here

 
  /**
   * {@inheritDoc}
   */
  public SteeringBehaviourOutput runFace(Point2d position, Vector2d orientation, double angularSpeed, double maxAngularAcc, Point2d target) {
    Vector2d alignTarget = new Vector2d();
    alignTarget.sub(target, position);
    if (alignTarget.length()<this.ignoreDistance)
      return this.alignBehaviour.runAlign(orientation, angularSpeed, maxAngularAcc, orientation);
    return this.alignBehaviour.runAlign(orientation, angularSpeed, maxAngularAcc, alignTarget);
  }
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.