Package eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math

Examples of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.ROVector2f


   
    // compute intersection of the line A and a line parallel to
    // the line A's normal passing through the origin of B
    Vector2f startA = vertsA[0];
    Vector2f endA = vertsA[1];
    ROVector2f startB = bodyB.getPosition();
    Vector2f endB = new Vector2f(endA);
    endB.sub(startA);
    endB.set(endB.y, -endB.x);
//    endB.add(startB);// TODO: inline endB into equations below, this last operation will be useless..
   
    //TODO: reuse mathutil.intersect
//    float d = (endB.y - startB.getY()) * (endA.x - startA.x);
//    d -= (endB.x - startB.getX()) * (endA.y - startA.y);
//   
//    float uA = (endB.x - startB.getX()) * (startA.y - startB.getY());
//    uA -= (endB.y - startB.getY()) * (startA.x - startB.getX());
//    uA /= d;
    float d = endB.y * (endA.x - startA.x);
    d -= endB.x * (endA.y - startA.y);
   
    float uA = endB.x * (startA.y - startB.getY());
    uA -= endB.y * (startA.x - startB.getX());
    uA /= d;
   
    Vector2f position = null;
   
    if ( uA < 0 ) { // the intersection is somewhere before startA
View Full Code Here


    this.color = Color.green;
   
    /* Position des Mondes und des JetAgenten */   
    Vector2D posMond = this.getEnvironment().getAgentPosition(100);
    Vector2D posRumpf = this.getEnvironment().getAgentPosition(0);
    ROVector2f pos = this.getPosition();
   
    /* Berechnung des Abstands zu Mond */
    double xAbstand = posMond.x - pos.getX();
    double yAbstand = posMond.y - pos.getY();
    double Abstand =  java.lang.Math.sqrt(xAbstand*xAbstand + yAbstand*yAbstand);
   
    /* Berechnung der relativen Lage zu Rumpfmittelpunkt und Verstärkung
     * Beachte: Abstand immer 2.5
     */
    Vector2f vKraft; float xKraft; float yKraft;
    xKraft = 40 * ((float) posRumpf.x - pos.getX());
    yKraft = 40 * ((float) posRumpf.y - pos.getY());
    vKraft = new Vector2f (xKraft, yKraft);
   
           
    /*Berechnung der Flugrichtung und Normalisierung des Vektors
    ROVector2f vHilf = this.getLastVelocity();
View Full Code Here

    hB.scale(0.5f);
    //Vector2f hB = MathUtil.scale(((Box) bodyB.getBodyShape()).getSize(), 0.5f);
    //Vector2f hA = MathUtil.scale(bodyA.getSize(), 0.5f);
    //Vector2f hB = MathUtil.scale(bodyB.getSize(), 0.5f);

    ROVector2f posA = bodyA.getPosition();
    ROVector2f posB = bodyB.getPosition();

    Matrix2f rotA = new Matrix2f(bodyA.getRotation());
    Matrix2f rotB = new Matrix2f(bodyB.getRotation());

    Matrix2f RotAT = rotA.transpose();
    Matrix2f RotBT = rotB.transpose();

    // unused?
//    Vector2f a1 = rotA.col1;
//    Vector2f a2 = rotA.col2;
//    Vector2f b1 = rotB.col1;
//    Vector2f b2 = rotB.col2;

    Vector2f dp = MathUtil.sub(posB,posA);
    Vector2f dA = MathUtil.mul(RotAT,dp);
    Vector2f dB = MathUtil.mul(RotBT,dp);

    Matrix2f C = MathUtil.mul(RotAT,rotB);
    Matrix2f absC = MathUtil.abs(C);
    Matrix2f absCT = absC.transpose();

    // Box A faces
    Vector2f faceA = MathUtil.abs(dA);
    faceA.sub(hA);
    faceA.sub(MathUtil.mul(absC,hB));
   
    if (faceA.x > 0.0f || faceA.y > 0.0f) {
      return 0;
    }

    // Box B faces
    Vector2f faceB = MathUtil.abs(dB);
    faceB.sub(MathUtil.mul(absCT,hA));
    faceB.sub(hB);
    //MathUtil.sub(MathUtil.sub(MathUtil.abs(dB),MathUtil.mul(absCT,hA)),hB);
    if (faceB.x > 0.0f || faceB.y > 0.0f) {
      return 0;
    }

    // Find best axis
    int axis;
    float separation;
    Vector2f normal;

    // Box A faces
    axis = FACE_A_X;
    separation = faceA.x;
    normal = dA.x > 0.0f ? rotA.col1 : MathUtil.scale(rotA.col1,-1);

    if (faceA.y > 1.05f * separation + 0.01f * hA.y)
    {
      axis = FACE_A_Y;
      separation = faceA.y;
      normal = dA.y > 0.0f ? rotA.col2 : MathUtil.scale(rotA.col2,-1);
    }

    // Box B faces
    if (faceB.x > 1.05f * separation + 0.01f * hB.x)
    {
      axis = FACE_B_X;
      separation = faceB.x;
      normal = dB.x > 0.0f ? rotB.col1 : MathUtil.scale(rotB.col1,-1);
    }

    if (faceB.y > 1.05f * separation + 0.01f * hB.y)
    {
      axis = FACE_B_Y;
      separation = faceB.y;
      normal = dB.y > 0.0f ? rotB.col2 : MathUtil.scale(rotB.col2,-1);
    }

    // Setup clipping plane data based on the separating axis
    Vector2f frontNormal, sideNormal;
    ClipVertex[] incidentEdge = new ClipVertex[] {new ClipVertex(), new ClipVertex()};
    float front, negSide, posSide;
    char negEdge, posEdge;

    // Compute the clipping lines and the line segment to be clipped.
    switch (axis)
    {
    case FACE_A_X:
      {
        frontNormal = normal;
        front = posA.dot(frontNormal) + hA.x;
        sideNormal = rotA.col2;
        float side = posA.dot(sideNormal);
        negSide = -side + hA.y;
        posSide =  side + hA.y;
        negEdge = EDGE3;
        posEdge = EDGE1;
        computeIncidentEdge(incidentEdge, hB, posB, rotB, frontNormal);
      }
      break;

    case FACE_A_Y:
      {
        frontNormal = normal;
        front = posA.dot(frontNormal) + hA.y;
        sideNormal = rotA.col1;
        float side = posA.dot(sideNormal);
        negSide = -side + hA.x;
        posSide =  side + hA.x;
        negEdge = EDGE2;
        posEdge = EDGE4;
        computeIncidentEdge(incidentEdge, hB, posB, rotB, frontNormal);
      }
      break;

    case FACE_B_X:
      {
        frontNormal = MathUtil.scale(normal,-1);
        front = posB.dot(frontNormal) + hB.x;
        sideNormal = rotB.col2;
        float side = posB.dot(sideNormal);
        negSide = -side + hB.y;
        posSide =  side + hB.y;
        negEdge = EDGE3;
        posEdge = EDGE1;
        computeIncidentEdge(incidentEdge, hA, posA, rotA, frontNormal);
      }
      break;

    case FACE_B_Y:
      {
        frontNormal = MathUtil.scale(normal,-1);
        front = posB.dot(frontNormal) + hB.y;
        sideNormal = rotB.col1;
        float side = posB.dot(sideNormal);
        negSide = -side + hB.x;
        posSide =  side + hB.x;
        negEdge = EDGE2;
        posEdge = EDGE4;
        computeIncidentEdge(incidentEdge, hA, posA, rotA, frontNormal);
View Full Code Here

  @Override
  public Double sense(DomPhysEnv env,
      PhysicsAgent2D<PhysicsEnvironment2D<?>> agent) {
   
    float masse = agent.getMass();
    ROVector2f impulsRichtung = agent.getVelocity();
    float impulsX = masse * impulsRichtung.getX();
    float impulsY = masse * impulsRichtung.getY();
   
    double richtung = env.getAgentAngle(agent.getID());
    double richtungRad = richtung * Math.PI / 180;
   
    double impuls = -1 *(impulsY * Math.cos(richtungRad) - impulsX* Math.sin(richtungRad));
 
View Full Code Here

  @Override
  public Double sense(DomPhysEnv env,
      PhysicsAgent2D<PhysicsEnvironment2D<?>> agent) {
   
    float masse = agent.getMass();
    ROVector2f impulsRichtung = agent.getVelocity();
    float impulsY = masse * impulsRichtung.getY();
    float impulsX = masse * impulsRichtung.getX();
       
    double richtung = env.getAgentAngle(agent.getID());
    double richtungRad = richtung * Math.PI / 180;   
   
    double impuls = -1 * (impulsX * Math.cos(richtungRad) + impulsY* Math.sin(richtungRad));
 
View Full Code Here

    this.maxAbstand = Double.MIN_VALUE;
    this.minAbstand = Double.MAX_VALUE;
      this.fitness = 0;
      this.geburt = runde;
     
      ROVector2f kraft = this.getForce();
      float x = kraft.getX() * -1;
    float y = kraft.getY() * -1;
    this.addForce(new Vector2f(x,y));
   
    ROVector2f geschwindigkeit = this.getVelocity();
      float x2 = geschwindigkeit.getX() * -1;
    float y2 = geschwindigkeit.getY() * -1;
    this.adjustVelocity(new Vector2f(x2,y2));
   
    float winkelgeschw = this.getAngularVelocity();
    this.adjustAngularVelocity(-1 * winkelgeschw);
   
 
View Full Code Here

   
    // compute intersection of the line A and a line parallel to
    // the line A's normal passing through the origin of B
    Vector2f startA = vertsA[0];
    Vector2f endA = vertsA[1];
    ROVector2f startB = bodyB.getPosition();
    Vector2f endB = new Vector2f(endA);
    endB.sub(startA);
    endB.set(endB.y, -endB.x);
//    endB.add(startB);// TODO: inline endB into equations below, this last operation will be useless..
   
    //TODO: reuse mathutil.intersect
//    float d = (endB.y - startB.getY()) * (endA.x - startA.x);
//    d -= (endB.x - startB.getX()) * (endA.y - startA.y);
//   
//    float uA = (endB.x - startB.getX()) * (startA.y - startB.getY());
//    uA -= (endB.y - startB.getY()) * (startA.x - startB.getX());
//    uA /= d;
    float d = endB.y * (endA.x - startA.x);
    d -= endB.x * (endA.y - startA.y);
   
    float uA = endB.x * (startA.y - startB.getY());
    uA -= endB.y * (startA.x - startB.getX());
    uA /= d;
   
    Vector2f position = null;
   
    if ( uA < 0 ) { // the intersection is somewhere before startA
View Full Code Here

    hB.scale(0.5f);
    //Vector2f hB = MathUtil.scale(((Box) bodyB.getShape()).getSize(), 0.5f);
    //Vector2f hA = MathUtil.scale(bodyA.getSize(), 0.5f);
    //Vector2f hB = MathUtil.scale(bodyB.getSize(), 0.5f);

    ROVector2f posA = bodyA.getPosition();
    ROVector2f posB = bodyB.getPosition();

    Matrix2f rotA = new Matrix2f(bodyA.getRotation());
    Matrix2f rotB = new Matrix2f(bodyB.getRotation());

    Matrix2f RotAT = rotA.transpose();
    Matrix2f RotBT = rotB.transpose();

    // unused?
//    Vector2f a1 = rotA.col1;
//    Vector2f a2 = rotA.col2;
//    Vector2f b1 = rotB.col1;
//    Vector2f b2 = rotB.col2;

    Vector2f dp = MathUtil.sub(posB,posA);
    Vector2f dA = MathUtil.mul(RotAT,dp);
    Vector2f dB = MathUtil.mul(RotBT,dp);

    Matrix2f C = MathUtil.mul(RotAT,rotB);
    Matrix2f absC = MathUtil.abs(C);
    Matrix2f absCT = absC.transpose();

    // Box A faces
    Vector2f faceA = MathUtil.abs(dA);
    faceA.sub(hA);
    faceA.sub(MathUtil.mul(absC,hB));
   
    if (faceA.x > 0.0f || faceA.y > 0.0f) {
      return 0;
    }

    // Box B faces
    Vector2f faceB = MathUtil.abs(dB);
    faceB.sub(MathUtil.mul(absCT,hA));
    faceB.sub(hB);
    //MathUtil.sub(MathUtil.sub(MathUtil.abs(dB),MathUtil.mul(absCT,hA)),hB);
    if (faceB.x > 0.0f || faceB.y > 0.0f) {
      return 0;
    }

    // Find best axis
    int axis;
    float separation;
    Vector2f normal;

    // Box A faces
    axis = FACE_A_X;
    separation = faceA.x;
    normal = dA.x > 0.0f ? rotA.col1 : MathUtil.scale(rotA.col1,-1);

    if (faceA.y > 1.05f * separation + 0.01f * hA.y)
    {
      axis = FACE_A_Y;
      separation = faceA.y;
      normal = dA.y > 0.0f ? rotA.col2 : MathUtil.scale(rotA.col2,-1);
    }

    // Box B faces
    if (faceB.x > 1.05f * separation + 0.01f * hB.x)
    {
      axis = FACE_B_X;
      separation = faceB.x;
      normal = dB.x > 0.0f ? rotB.col1 : MathUtil.scale(rotB.col1,-1);
    }

    if (faceB.y > 1.05f * separation + 0.01f * hB.y)
    {
      axis = FACE_B_Y;
      separation = faceB.y;
      normal = dB.y > 0.0f ? rotB.col2 : MathUtil.scale(rotB.col2,-1);
    }

    // Setup clipping plane data based on the separating axis
    Vector2f frontNormal, sideNormal;
    ClipVertex[] incidentEdge = new ClipVertex[] {new ClipVertex(), new ClipVertex()};
    float front, negSide, posSide;
    char negEdge, posEdge;

    // Compute the clipping lines and the line segment to be clipped.
    switch (axis)
    {
    case FACE_A_X:
      {
        frontNormal = normal;
        front = posA.dot(frontNormal) + hA.x;
        sideNormal = rotA.col2;
        float side = posA.dot(sideNormal);
        negSide = -side + hA.y;
        posSide =  side + hA.y;
        negEdge = EDGE3;
        posEdge = EDGE1;
        computeIncidentEdge(incidentEdge, hB, posB, rotB, frontNormal);
      }
      break;

    case FACE_A_Y:
      {
        frontNormal = normal;
        front = posA.dot(frontNormal) + hA.y;
        sideNormal = rotA.col1;
        float side = posA.dot(sideNormal);
        negSide = -side + hA.x;
        posSide =  side + hA.x;
        negEdge = EDGE2;
        posEdge = EDGE4;
        computeIncidentEdge(incidentEdge, hB, posB, rotB, frontNormal);
      }
      break;

    case FACE_B_X:
      {
        frontNormal = MathUtil.scale(normal,-1);
        front = posB.dot(frontNormal) + hB.x;
        sideNormal = rotB.col2;
        float side = posB.dot(sideNormal);
        negSide = -side + hB.y;
        posSide =  side + hB.y;
        negEdge = EDGE3;
        posEdge = EDGE1;
        computeIncidentEdge(incidentEdge, hA, posA, rotA, frontNormal);
      }
      break;

    case FACE_B_Y:
      {
        frontNormal = MathUtil.scale(normal,-1);
        front = posB.dot(frontNormal) + hB.y;
        sideNormal = rotB.col1;
        float side = posB.dot(sideNormal);
        negSide = -side + hB.x;
        posSide =  side + hB.x;
        negEdge = EDGE2;
        posEdge = EDGE4;
        computeIncidentEdge(incidentEdge, hA, posA, rotA, frontNormal);
View Full Code Here

   * @return The points building up a box at this position and rotation
   */
  public Vector2f[] getPoints(ROVector2f pos, float rotation) {
    Matrix2f R = new Matrix2f(rotation);
    Vector2f[] pts = new Vector2f[4];
    ROVector2f h = MathUtil.scale(getSize(),0.5f);

    pts[0] = MathUtil.mul(R, new Vector2f(-h.getX(), -h.getY()));
    pts[0].add(pos);
    pts[1] = MathUtil.mul(R, new Vector2f(h.getX(), -h.getY()));
    pts[1].add(pos);
    pts[2] = MathUtil.mul(R, new Vector2f( h.getX(),  h.getY()));
    pts[2].add(pos);
    pts[3] = MathUtil.mul(R, new Vector2f(-h.getX(),  h.getY()));
    pts[3].add(pos);

    return pts;
  }
View Full Code Here

TOP

Related Classes of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.ROVector2f

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.