コード例 #1
1
    private Location NextEdge(double direction) {
      direction = AcceptableAngle(direction);
      Double topleftangle = AcceptableAngle(myCenter.difference(TOP_LEFT).getDirection());
      Double toprightangle = AcceptableAngle(myCenter.difference(TOP_RIGHT).getDirection());
      Double bottomleftangle = AcceptableAngle(myCenter.difference(BOTTOM_LEFT).getDirection());
      Double bottomrightangle = AcceptableAngle(myCenter.difference(BOTTOM_RIGHT).getDirection());

      if (direction >= topleftangle && direction < toprightangle) {
        double Xcoordinate =
            myCenter.getX() + myCenter.getY() * Math.tan(Math.toRadians(direction - 270));
        return new Location(Xcoordinate, MIN_Y);
      } else if (direction < bottomrightangle || direction >= toprightangle) {
        double Ycoordinate =
            myCenter.getY() + (MAX_X - myCenter.getX()) * Math.tan(Math.toRadians(direction));
        return new Location(MAX_X, Ycoordinate);
      } else if (direction >= bottomrightangle && direction < bottomleftangle) {
        double Xcoordinate =
            myCenter.getX() - (MAX_Y - myCenter.getY()) * Math.tan(Math.toRadians(direction - 90));
        return new Location(Xcoordinate, MAX_Y);
      } else {
        double Ycoordinate =
            myCenter.getY() - myCenter.getX() * Math.tan(Math.toRadians(direction - 180));
        return new Location(MIN_X, Ycoordinate);
      }
    }
コード例 #2
1
  public Geographic2dCoordinate destination(
      final double latitude,
      final double longitude,
      final double initialBearing,
      final double distance) {

    final double b = Math.toRadians(initialBearing);
    final double d = distance / sphere.getRadius();
    final double lat1 = Math.toRadians(latitude);
    final double lon1 = Math.toRadians(longitude);

    double lat2 = lat1 + d * Math.cos(b);
    final double dLat = lat2 - lat1;
    final double dPhi =
        Math.log(Math.tan(lat2 / 2 + Math.PI / 4) / Math.tan(lat1 / 2 + Math.PI / 4));
    final double q =
        (!Double.isNaN(dLat / dPhi)) ? dLat / dPhi : Math.cos(lat1); // E-W line gives dPhi=0

    final double dLon = d * Math.sin(b) / q;

    // check for some daft bugger going past the pole, normalise latitude if
    // so
    if (Math.abs(lat2) > Math.PI / 2) {
      lat2 = lat2 > 0 ? Math.PI - lat2 : -(Math.PI - lat2);
    }

    final double lon2 = (lon1 + dLon + Math.PI) % (2 * Math.PI) - Math.PI;

    return new Geographic2dCoordinate(Math.toDegrees(lat2), Math.toDegrees(lon2));
  }
コード例 #3
0
    /** {@inheritDoc} */
    @Override
    Position pointOnBearing0(
        double startLatDegrees,
        double startLonDegrees,
        double distanceMeters,
        double bearingDegrees) {
      // Convert to radians
      startLatDegrees = Math.toRadians(startLatDegrees);
      startLonDegrees = Math.toRadians(startLonDegrees);
      bearingDegrees = Math.toRadians(bearingDegrees);
      // the earth's radius in meters
      final double earthRadius = EARTH_MEAN_RADIUS_KM * 1000.0;

      double endLat =
          Math.asin(
              Math.sin(startLatDegrees) * Math.cos(distanceMeters / earthRadius)
                  + Math.cos(startLatDegrees)
                      * Math.sin(distanceMeters / earthRadius)
                      * Math.cos(bearingDegrees));
      double endLon =
          startLonDegrees
              + Math.atan2(
                  Math.sin(bearingDegrees)
                      * Math.sin(distanceMeters / earthRadius)
                      * Math.cos(startLatDegrees),
                  Math.cos(distanceMeters / earthRadius)
                      - Math.sin(startLatDegrees) * Math.sin(endLat));
      return Position.create(Math.toDegrees(endLat), Math.toDegrees(endLon));
    }
コード例 #4
0
ファイル: Matrix4x3dTest.java プロジェクト: huhlig/JOML
 public static void testPositiveXRotateXY() {
   Vector3d dir = new Vector3d();
   Matrix4x3d m =
       new Matrix4x3d().rotateY((float) Math.toRadians(90)).rotateX((float) Math.toRadians(45));
   m.positiveX(dir);
   TestUtil.assertVector3dEquals(new Vector3d(0, 1, 1).normalize(), dir, 1E-7f);
 }
コード例 #5
0
ファイル: StdDraw.java プロジェクト: ci010/Practice
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees.
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
コード例 #6
0
ファイル: TargetBlock.java プロジェクト: matter123/Spout
  /**
   * Set the values, all constructors uses this function
   *
   * @param loc location of the view
   * @param maxDistance how far it checks for blocks
   * @param viewHeight where the view is positioned in y-axis
   * @param checkDistance how often to check for blocks, the smaller the more precise
   */
  private void setValues(
      Location loc,
      int maxDistance,
      double viewHeight,
      double checkDistance,
      TIntHashSet transparent) {
    this.maxDistance = maxDistance;
    this.checkDistance = checkDistance;
    curDistance = 0;
    int xRotation = (int) (loc.getYaw() + 90) % 360;
    int yRotation = (int) loc.getPitch() * -1;

    double h = checkDistance * Math.cos(Math.toRadians(yRotation));

    offset =
        new Vector(
            (h * Math.cos(Math.toRadians(xRotation))),
            (checkDistance * Math.sin(Math.toRadians(yRotation))),
            (h * Math.sin(Math.toRadians(xRotation))));

    targetPosDouble = loc.add(0, viewHeight, 0).toVector();
    targetPos = targetPosDouble.toBlockVector();
    prevPos = targetPos;
    transparentBlocks = transparent;
    if (transparentBlocks == null) {
      transparentBlocks = new TIntHashSet(new int[] {0});
    }
  }
コード例 #7
0
ファイル: Vec2.java プロジェクト: Sangheli/NeuroBot
  public static double getAngleToTarget(BaseModel t1, BaseModel t2) {
    Vec2 forVec =
        Vec2.getVector(
            t1.getPosX(),
            t1.getPosY(),
            t1.getPosX() + Math.cos(Math.toRadians(t1.getRotation())) * 10,
            t1.getPosY() + Math.sin(Math.toRadians(t1.getRotation())) * 10);
    Vec2 tarVec = Vec2.getVector(t1.getPosX(), t1.getPosY(), t2.getPosX(), t2.getPosY());

    double scalar = Vec2.getScalarMultip(forVec, tarVec);

    double modFV = Math.sqrt(forVec.vX * forVec.vX + forVec.vY * forVec.vY);
    double modTV = Math.sqrt(tarVec.vX * tarVec.vX + tarVec.vY * tarVec.vY);

    double cosa = scalar / (modFV * modTV);

    double ang = Math.toDegrees(Math.acos(cosa));

    double znak = getRelativePositionTarget(t1, t2);
    znak = znak / Math.abs(znak);

    if (Double.isNaN(znak)) {
      znak = 0;
    }

    if (Double.isNaN(ang)) {
      ang = 0;
    }

    return ang * znak;
  }
コード例 #8
0
ファイル: PVectorI2ITest.java プロジェクト: io7m/jtensors
  @Override
  @Test
  public void testAngle() {
    final AlmostEqualDouble.ContextRelative ec = TestUtilities.getDoubleEqualityContext3dp();

    {
      final PVectorI2I<T> v0 = new PVectorI2I<T>(1, 0);
      final PVectorI2I<T> v1 = new PVectorI2I<T>(1, 0);
      final double angle = PVectorI2I.angle(v0, v1);

      Assert.assertTrue(AlmostEqualDouble.almostEqual(ec, angle, 0.0));
    }

    {
      final int x = (int) (Math.random() * 200);
      final int y = (int) (Math.random() * 200);
      final PVectorI2I<T> v0 = new PVectorI2I<T>(x, y);
      final PVectorI2I<T> v1 = new PVectorI2I<T>(y, -x);
      final double angle = PVectorI2I.angle(v0, v1);

      Assert.assertTrue(AlmostEqualDouble.almostEqual(ec, angle, Math.toRadians(90)));
    }

    {
      final int x = (int) (Math.random() * 200);
      final int y = (int) (Math.random() * 200);
      final PVectorI2I<T> v0 = new PVectorI2I<T>(x, y);
      final PVectorI2I<T> v1 = new PVectorI2I<T>(-y, x);
      final double angle = PVectorI2I.angle(v0, v1);

      Assert.assertTrue(AlmostEqualDouble.almostEqual(ec, angle, Math.toRadians(90)));
    }
  }
コード例 #9
0
  @Test
  public void testOperators() {
    try {
      assertEquals(2d, Expression.evaluate("1 + 1").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(0d, Expression.evaluate("1 - 1").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("1 * 2").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("6 / 3").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("6 % 4").toDouble(), FuzzyEquals.TOLERANCE);

      assertTrue(Expression.evaluate("true && true").toBoolean());
      assertFalse(Expression.evaluate("true AND false").toBoolean());
      assertTrue(Expression.evaluate("true || true").toBoolean());
      assertTrue(Expression.evaluate("true OR false").toBoolean());
      assertFalse(Expression.evaluate("not(true)").toBoolean());

      assertEquals(6d, Expression.evaluate("max(2,3,6)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("min(2,3,6)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("floor(2.2)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(4d, Expression.evaluate("ceil(3.6)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(-3d, Expression.evaluate("neg(3)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(3d, Expression.evaluate("abs(neg(3))").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.cos(Math.toRadians(180)),
          Expression.evaluate("cos(rad(180))").toDouble(),
          FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.sin(Math.toRadians(90)),
          Expression.evaluate("sin(rad(90))").toDouble(),
          FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.tan(Math.toRadians(45)),
          Expression.evaluate("tan(rad(45))").toDouble(),
          FuzzyEquals.TOLERANCE);
      assertEquals(Math.acos(0), Expression.evaluate("acos(0)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.asin(180), Expression.evaluate("asin(180)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(Math.atan(1), Expression.evaluate("atan(1)").toDouble(), FuzzyEquals.TOLERANCE);

      assertTrue(Expression.evaluate("1 == 1").toBoolean());
      assertTrue(Expression.evaluate("1 > 0").toBoolean());
      assertTrue(Expression.evaluate("1 < 2").toBoolean());
      assertTrue(Expression.evaluate("1 <= 2").toBoolean());

      assertTrue(Expression.evaluate("1 >= 1").toBoolean());

      assertEquals("b", Expression.evaluate("substr(abcd,1,2)").toString());

      Expression exp = new Expression("dateDifference(01/01/2006, 01/05/2006, |DAY|)");
      exp.setResolver(new SimpleResolver());
      assertEquals(4d, exp.evaluate().toDouble(), FuzzyEquals.TOLERANCE);

      exp = new Expression("max(1, 2, NULL)");
      exp.setResolver(new SimpleResolver());
      assertEquals("max(1, 2, NULL)", exp.evaluate().toString());

    } catch (InvalidExpressionException e) {
      e.printStackTrace();
      fail();
    }
  }
コード例 #10
0
ファイル: Helper.java プロジェクト: AdamStuart/libFX
  public static Point2D latLongToPixel(
      final Dimension2D MAP_DIMENSION,
      final Point2D UPPER_LEFT,
      final Point2D LOWER_RIGHT,
      final Point2D LOCATION) {
    final double LATITUDE = LOCATION.getX();
    final double LONGITUDE = LOCATION.getY();
    final double MAP_WIDTH = MAP_DIMENSION.getWidth();
    final double MAP_HEIGHT = MAP_DIMENSION.getHeight();

    final double WORLD_MAP_WIDTH =
        ((MAP_WIDTH / (LOWER_RIGHT.getY() - UPPER_LEFT.getY())) * 360) / (2 * Math.PI);
    final double MAP_OFFSET_Y =
        (WORLD_MAP_WIDTH
            / 2
            * Math.log10(
                (1 + Math.sin(Math.toRadians(LOWER_RIGHT.getX())))
                    / (1 - Math.sin(Math.toRadians(LOWER_RIGHT.getX())))));

    final double X =
        (LONGITUDE - UPPER_LEFT.getY()) * (MAP_WIDTH / (LOWER_RIGHT.getY() - UPPER_LEFT.getY()));
    final double Y =
        MAP_HEIGHT
            - ((WORLD_MAP_WIDTH
                    / 2
                    * Math.log10(
                        (1 + Math.sin(Math.toRadians(LATITUDE)))
                            / (1 - Math.sin(Math.toRadians(LATITUDE)))))
                - MAP_OFFSET_Y);

    return new Point2D(X, Y);
  }
コード例 #11
0
ファイル: RenderUtil.java プロジェクト: Tektor/tallDoors
  public static void renderOutline(
      double height, double width, double depth, double angle, Entity base) {
    Tessellator tess = Tessellator.instance;

    tess.startDrawingQuads();

    double a, b, e, d;
    a = Math.cos(Math.toRadians(90 - angle)) * height;
    b = Math.sin(Math.toRadians(90 - angle)) * height;
    d = Math.cos(Math.toRadians(angle)) * depth;
    e = Math.sin(Math.toRadians(angle)) * depth;

    tess.addVertexWithUV(0, b, 0 - a, 0, width);
    tess.addVertexWithUV(0, b + e, d - a, depth, width);
    tess.addVertexWithUV(width, b + e, d - a, depth, 0);
    tess.addVertexWithUV(width, b, -a, 0, 0);
    // right
    tess.addVertexWithUV(0, 0, 0, 0, 0);
    tess.addVertexWithUV(0, e, d, depth, 0);
    tess.addVertexWithUV(0, b + e, d - a, depth, height);
    tess.addVertexWithUV(0, b, -a, 0, height);
    // bottom
    tess.addVertexWithUV(0, 0, 0, width, 0);
    tess.addVertexWithUV(width, 0, 0, 0, 0);
    tess.addVertexWithUV(width, e, d, 0, depth);
    tess.addVertexWithUV(0, e, d, width, depth);
    // left
    tess.addVertexWithUV(width, 0, 0, 0, 0);
    tess.addVertexWithUV(width, b, -a, 0, height);
    tess.addVertexWithUV(width, b + e, d - a, depth, height);
    tess.addVertexWithUV(width, e, d, depth, 0);

    tess.draw();
  }
コード例 #12
0
ファイル: RenderUtil.java プロジェクト: Tektor/tallDoors
  public static void renderFrontBack(
      double height, double width, double depth, double angle, Entity base) {

    Tessellator tess = Tessellator.instance;

    tess.startDrawingQuads();

    double a, b, e, d;
    a = Math.cos(Math.toRadians(90 - angle)) * height;
    b = Math.sin(Math.toRadians(90 - angle)) * height;
    d = Math.cos(Math.toRadians(angle)) * depth;
    e = Math.sin(Math.toRadians(angle)) * depth;

    // front
    tess.addVertexWithUV(0, 0, 0, width, 0.0);
    tess.addVertexWithUV(0, b, 0 - a, width, height);
    tess.addVertexWithUV(width, b, 0 - a, 0, height);
    tess.addVertexWithUV(width, 0, 0, 0, 0);
    // back
    tess.addVertexWithUV(0, e, d, width, 0.0);
    tess.addVertexWithUV(width, e, d, 0, 0);
    tess.addVertexWithUV(width, e + b, d - a, 0, height);
    tess.addVertexWithUV(0, e + b, d - a, width, height);

    tess.draw();
  }
コード例 #13
0
ファイル: OctopusForm.java プロジェクト: N4m/MinecraftTLA
  private void formOctopus() {
    Location location = player.getLocation();
    newblocks.clear();
    for (double theta = startangle; theta < startangle + angle; theta += 10) {
      double rtheta = Math.toRadians(theta);
      Block block =
          location
              .clone()
              .add(new Vector(radius * Math.cos(rtheta), 0, radius * Math.sin(rtheta)))
              .getBlock();
      addWater(block);
    }

    double tentacleangle =
        (new Vector(1, 0, 0)).angle(player.getEyeLocation().getDirection()) + dta / 2;

    int astep = animstep;
    for (double tangle = tentacleangle; tangle < tentacleangle + 360; tangle += dta) {
      astep += 1;
      double phi = Math.toRadians(tangle);
      tentacle(
          location.clone().add(new Vector(radius * Math.cos(phi), 0, radius * Math.sin(phi))),
          astep);
    }

    for (TempBlock block : blocks) {
      if (!newblocks.contains(block)) block.revertBlock();
    }

    blocks.clear();

    blocks.addAll(newblocks);

    if (blocks.isEmpty()) remove();
  }
コード例 #14
0
 public CassiniProjection() {
   projectionLatitude = Math.toRadians(0);
   projectionLongitude = Math.toRadians(0);
   minLongitude = Math.toRadians(-90);
   maxLongitude = Math.toRadians(90);
   initialize();
 }
コード例 #15
0
  @Override
  public boolean attackEntityAsMob(Entity victim) {
    float attackDamage =
        (float) getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    int knockback = 0;

    if (victim instanceof EntityLivingBase) {
      attackDamage +=
          EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) victim);
      knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) victim);
    }

    boolean attacked = victim.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage);

    if (attacked) {
      if (knockback > 0) {
        double vx = -Math.sin(Math.toRadians(rotationYaw)) * knockback * 0.5;
        double vy = 0.1;
        double vz = Math.cos(Math.toRadians(rotationYaw)) * knockback * 0.5;
        victim.addVelocity(vx, vy, vz);
        motionX *= 0.6;
        motionZ *= 0.6;
      }

      if (victim instanceof EntityLivingBase) {
        // EnchantmentThorns.func_92096_a(this, (EntityLivingBase) victim, rand);
      }

      setLastAttacker(victim);
    }

    return attacked;
  }
コード例 #16
0
ファイル: Bullet.java プロジェクト: blazingcloud/ouyatron
  public Bullet(Player shooter, float translationX, float translationY, float rotation, int color) {
    super(c_bulletRadius);
    this.translation.set(translationX, translationY);
    this.rotation = rotation;
    this.color = color;
    this.shooter = shooter;

    float fwdX = (float) Math.sin(Math.toRadians(-rotation));
    float fwdY = (float) Math.cos(Math.toRadians(-rotation));
    this.flight.set(c_bulletSpeed * fwdX, c_bulletSpeed * fwdY);

    startTime = System.currentTimeMillis();

    setCollisionListener(
        new CollisionListener() {
          @Override
          public void onCollide(PointF prev, RenderObject me, RenderObject other) {
            if (other instanceof Player && other != Bullet.this.shooter) {
              Player p = (Player) other;
              p.doBurst();
              p.die();
              Bullet.this.destroy();
            } else if (other instanceof Wall) {
              Bullet.this.destroy();
            } else if (other instanceof Asteroid) {
              Asteroid a = (Asteroid) other;
              Bullet.this.destroy();
              a.asteroidDeath();
              a.destroy();
            }
          }
        });
  }
コード例 #17
0
 public LambertEqualAreaConicProjection(boolean south) {
   minLatitude = Math.toRadians(0);
   maxLatitude = Math.toRadians(90);
   projectionLatitude1 = south ? -MapMath.QUARTERPI : MapMath.QUARTERPI;
   projectionLatitude2 = south ? -MapMath.HALFPI : MapMath.HALFPI;
   initialize();
 }
コード例 #18
0
  @Override
  public void progress() {
    if ((System.currentTimeMillis() - time) >= interval) {
      time = System.currentTimeMillis();

      // Compute effect
      for (LivingEntity entity : EntityTools.getLivingEntitiesAroundPoint(origin, RADIUS)) {
        affect(entity);
      }

      if (noDisplayTick <= 0) {
        // Compute particles
        for (double theta = 0; theta < 360; theta += 36) {
          for (double phi = 0; phi < 360; phi += 36) {
            double x =
                particleDistance * Math.cos(Math.toRadians(theta)) * Math.sin(Math.toRadians(phi));
            double y =
                particleDistance * Math.sin(Math.toRadians(theta)) * Math.sin(Math.toRadians(phi));
            double z = particleDistance * Math.cos(Math.toRadians(phi));
            origin.getWorld().playEffect(origin.clone().add(x, y, z), Effect.SMOKE, 4, (int) RANGE);
          }
        }
        particleDistance -= 1;
        if (particleDistance < 0) {
          particleDistance = RADIUS;
        }
        noDisplayTick = 4;
      }
      noDisplayTick--;
    }
  }
コード例 #19
0
ファイル: PlayerObject.java プロジェクト: kierendavies/csc
 public void moveInDirection(float direction) {
   oldPosition = this.getPosition();
   incrementPosition(
       (float) Math.sin(Math.toRadians(direction)) * 20,
       -(float) Math.cos(Math.toRadians(direction)) * 20);
   setDirection(direction);
 }
コード例 #20
0
  /**
   * reference point created with proj4 command : <code>
   * proj -f "%.8f" +proj=sterea +ellps=bessel +lon_0=5.38763888888889 +lat_0=52.15616055555555 +k=0.9999079
   * +x_0=155000 +y_0=463000.0
   * 6.610765 53.235916
   * 236655.91462443 583827.76880699
   * </code>
   *
   * @throws IllegalArgumentException
   * @throws ProjectionException
   */
  public void testAccuracy() throws IllegalArgumentException, ProjectionException {

    Point2d sourcePoint = new Point2d(Math.toRadians(6.610765), Math.toRadians(53.235916));
    Point2d targetPoint = new Point2d(236655.91462443, 583827.76880699);

    doForwardAndInverse(projection_28992, sourcePoint, targetPoint);
  }
コード例 #21
0
 private static double computeAngleBetween(LatLng from, LatLng to) {
   return distanceRadians(
       Math.toRadians(from.latitude),
       Math.toRadians(from.longitude),
       Math.toRadians(to.latitude),
       Math.toRadians(to.longitude));
 }
コード例 #22
0
ファイル: Utilities.java プロジェクト: kim0z/gpslogger
  /**
   * Uses the Haversine formula to calculate the distnace between to lat-long coordinates
   *
   * @param latitude1 The first point's latitude
   * @param longitude1 The first point's longitude
   * @param latitude2 The second point's latitude
   * @param longitude2 The second point's longitude
   * @return The distance between the two points in meters
   */
  public static double CalculateDistance(
      double latitude1, double longitude1, double latitude2, double longitude2) {
    /*
    Haversine formula:
    A = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
    C = 2.atan2(√a, √(1−a))
    D = R.c
    R = radius of earth, 6371 km.
    All angles are in radians
    */

    double deltaLatitude = Math.toRadians(Math.abs(latitude1 - latitude2));
    double deltaLongitude = Math.toRadians(Math.abs(longitude1 - longitude2));
    double latitude1Rad = Math.toRadians(latitude1);
    double latitude2Rad = Math.toRadians(latitude2);

    double a =
        Math.pow(Math.sin(deltaLatitude / 2), 2)
            + (Math.cos(latitude1Rad)
                * Math.cos(latitude2Rad)
                * Math.pow(Math.sin(deltaLongitude / 2), 2));

    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    return 6371 * c * 1000; // Distance in meters
  }
コード例 #23
0
  private Location calculateNextLocation(Location loc, double distance) {
    Random rand = new Random();
    int minAngle = 0;
    int maxAngle = 360;
    int randomAngle = rand.nextInt((maxAngle - minAngle) + 1) + minAngle;
    double bearing = Math.toRadians(randomAngle);

    double lat1 = Math.toRadians(loc.Latitude);
    double lon1 = Math.toRadians(loc.Longtitude);

    double lat2 =
        Math.asin(
            Math.sin(lat1) * Math.cos(distance / EarthRadius)
                + Math.cos(lat1) * Math.sin(distance / EarthRadius) * Math.cos(bearing));

    double lon2 =
        lon1
            + Math.atan2(
                Math.sin(bearing) * Math.sin(distance / EarthRadius) * Math.cos(lat1),
                Math.cos(distance / EarthRadius) - Math.sin(lat1) * Math.sin(lat2));

    lat2 = Math.toDegrees(lat2);
    lon2 = Math.toDegrees(lon2);

    return LatLongToXYZ(lat2, lon2);
  }
コード例 #24
0
  public static Transform rotate(final double angle, final Vector vector) {
    vector.normalize();

    final double sin = Math.sin(Math.toRadians(angle));
    final double cos = Math.cos(Math.toRadians(angle));

    final double[][] m = new double[4][4];

    m[0][0] = vector.getX() * vector.getX() + (1.0D - vector.getX() * vector.getX()) * cos;
    m[0][1] = vector.getX() * vector.getY() * (1.0D - cos) - vector.getZ() * sin;
    m[0][2] = vector.getX() * vector.getZ() * (1.0D - cos) + vector.getY() * sin;
    m[0][3] = 0.0D;

    m[1][0] = vector.getX() * vector.getY() * (1.0D - cos) + vector.getZ() * sin;
    m[1][1] = vector.getY() * vector.getY() + (1.0D - vector.getY() * vector.getY()) * cos;
    m[1][2] = vector.getY() * vector.getZ() * (1.0D - cos) - vector.getX() * sin;
    m[1][3] = 0.0D;

    m[2][0] = vector.getX() * vector.getZ() * (1.0D - cos) - vector.getY() * sin;
    m[2][1] = vector.getY() * vector.getZ() * (1.0D - cos) + vector.getX() * sin;
    m[2][2] = vector.getZ() * vector.getZ() + (1.0D - vector.getZ() * vector.getZ()) * cos;
    m[2][3] = 0.0D;

    m[3][0] = 0.0D;
    m[3][1] = 0.0D;
    m[3][2] = 0.0D;
    m[3][3] = 1.0D;

    final Matrix matrix = Matrix.newInstance(m);
    final Matrix matrixInversed = matrix.transpose();

    return newInstance(matrix, matrixInversed);
  }
コード例 #25
0
ファイル: DummyGame.java プロジェクト: lwjglgamedev/lwjglbook
  @Override
  public void update(float interval, MouseInput mouseInput) {
    // Update camera based on mouse
    if (mouseInput.isRightButtonPressed()) {
      Vector2f rotVec = mouseInput.getDisplVec();
      camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
    }

    // Update camera position
    Vector3f prevPos = new Vector3f(camera.getPosition());
    camera.movePosition(
        cameraInc.x * CAMERA_POS_STEP,
        cameraInc.y * CAMERA_POS_STEP,
        cameraInc.z * CAMERA_POS_STEP);
    // Check if there has been a collision. If true, set the y position to
    // the maximum height
    float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE;
    if (camera.getPosition().y <= height) {
      camera.setPosition(prevPos.x, prevPos.y, prevPos.z);
    }

    lightAngle += angleInc;
    if (lightAngle < 0) {
      lightAngle = 0;
    } else if (lightAngle > 180) {
      lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();
  }
コード例 #26
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2D = (Graphics2D) g.create();

    // Draw each space
    for (int i = 0, degrees = 0; i < imageNames.size() / 2; ++i) {
      g2D.setColor(
          WHEEL_COLORS.get(imageNames.get(i).substring(0, imageNames.get(i).indexOf('.'))));
      g2D.fillArc(150, 45, 480, 480, degrees, DEGREES_EACH);
      degrees += DEGREES_EACH;
    }

    // Set the origin and rotate before drawing the images
    g2D.translate(390, 285);
    g2D.rotate(Math.toRadians(-100));

    // Draw wheel spaces
    for (int i = 0; i < imageNames.size() / 2; ++i) {
      g2D.drawImage(IMAGES.get(imageNames.get(i)), -42, 0, this);
      g2D.rotate(Math.toRadians(-DEGREES_EACH));
    }

    // Reset origin
    g2D.translate(-390, -285);

    // Draw the arrow to indicate where the wheel stopped
    g.drawImage(IMAGES.get("arrow.png"), 370, 10, this);
  }
コード例 #27
0
 public double calculationByDistance(GeoPoint gpOrigem, GeoPoint gpDestino) {
   int Radius = 6371; // radius of earth in Km
   double c = 0f;
   if (gpOrigem != null && gpDestino != null) {
     double lat1 = gpOrigem.getLatitudeE6() / 1E6;
     double lat2 = gpDestino.getLatitudeE6() / 1E6;
     double lon1 = gpOrigem.getLongitudeE6() / 1E6;
     double lon2 = gpDestino.getLongitudeE6() / 1E6;
     double dLat = Math.toRadians(lat2 - lat1);
     double dLon = Math.toRadians(lon2 - lon1);
     double a =
         Math.sin(dLat / 2) * Math.sin(dLat / 2)
             + Math.cos(Math.toRadians(lat1))
                 * Math.cos(Math.toRadians(lat2))
                 * Math.sin(dLon / 2)
                 * Math.sin(dLon / 2);
     c = 2 * Math.asin(Math.sqrt(a));
     double valueResult = Radius * c;
     double km = valueResult / 1;
     DecimalFormat newFormat = new DecimalFormat("####");
     Integer kmInDec = Integer.valueOf(newFormat.format(km));
     double meter = valueResult % 1000;
     double meterInDec = Integer.valueOf(newFormat.format(meter));
     Log.i("Radius Value", "" + valueResult + "   KM  " + kmInDec + " Meter   " + meterInDec);
   }
   return Radius * c;
 }
コード例 #28
0
 private void checkMainBase(FakeMessage msg) {
   EntityKnowledge mainBase = getMainBase();
   if ((mainBase != null) && (msg.getSender() == mainBase.getID())) {
     x = (int) -(Math.cos(Math.toRadians(msg.getAngle())) * msg.getDistance());
     y = (int) -(Math.sin(Math.toRadians(msg.getAngle())) * msg.getDistance());
   }
 }
コード例 #29
0
  public static float[] getDirectionDot(double[] values) {
    double yawAngle = -Math.toRadians(values[0]); // 获取Yaw轴旋转角度弧度
    double pitchAngle = -Math.toRadians(values[1]); // 获取Pitch轴旋转角度弧度
    double rollAngle = -Math.toRadians(values[2]); // 获取Roll轴旋转角度弧度
    /*
     * 算法思想为手机在一个姿态后首先虚拟出一个重力向量,
     * 然后三次选装把手机恢复到原始姿态,期间重力向量伴随
     * 变化,最后重力向量往手机平面上一投影。
     */
    // 虚拟一个重力向量
    double[] gVector = {0, 0, -100, 1};

    /*
     * 在这里需要注意沿三个空间方向x,y,z轴所旋转的角度的恢复顺序,由于Yaw轴始终指向竖直向上(重力加速度反向),和
     * 标准的空间坐标系的z轴一样,所以 可以通过负向旋转直接进行角度恢复;沿yaw轴将转过的角度恢复后,此时的pitch轴
     * 就变成了空间坐标系中的x轴,沿pitch(x)轴将 转过 的角度恢复,此时的roll轴就修正为了空间坐标系中的y轴,最后
     * 按照y轴将转过的角度恢复,则此时手机平面所在的平面变成了空间坐标 系中x-y平面,而附着于手机平面上的重力加速度
     * 的则是一个与手机平面相交的向量,将该向量投影到手机平面,通过投影点就可以计算出小球要滚动的方向
     * 如果不按照上述顺序进行角度恢复,则空间坐标的计算转换将会非常复杂,而上述方法中每一步的角度恢复都是基于标准
     * 的坐标系轴,而对标准坐标轴的转换在计算机图形
     * 学中很容易实现
     */
    // yaw轴恢复
    gVector = RotateUtil.yawRotate(yawAngle, gVector);
    // pitch轴恢复
    gVector = RotateUtil.pitchRotate(pitchAngle, gVector);
    // roll轴恢复
    gVector = RotateUtil.rollRotate(rollAngle, gVector);
    double mapX = gVector[0];
    double mapY = gVector[1];
    float[] result = {(float) mapX, (float) mapY};
    return result;
  }
コード例 #30
0
  protected void update() {

    // TODO Must be review
    double delta = 2;
    double center = (getOuterRadius() + getInnerRadius()) / 2;
    System.out.println("update " + getLength());
    // Arc lenght angle
    double arcAngleLengthInRadians = Math.toRadians(getLength());

    // Angle rotation of the item
    double itemAngleInRadians = Math.toRadians(getStartAngle() + ANGLE_TO_START_AT_ZERO_DEGREE);

    moveTo.setX((center - delta) * Math.cos(itemAngleInRadians));
    moveTo.setY((center - delta) * Math.sin(itemAngleInRadians));

    lineTo.setX((center + delta) * Math.cos(itemAngleInRadians));
    lineTo.setY((center + delta) * Math.sin(itemAngleInRadians));

    arcTo.setX((center + delta) * Math.cos(itemAngleInRadians + arcAngleLengthInRadians));
    arcTo.setY((center + delta) * Math.sin(itemAngleInRadians + arcAngleLengthInRadians));
    arcTo.setRadiusX(center);
    arcTo.setRadiusY(center);
    arcTo.setSweepFlag(true);

    lineTo2.setX((center - delta) * Math.cos(itemAngleInRadians + arcAngleLengthInRadians));
    lineTo2.setY((center - delta) * Math.sin(itemAngleInRadians + arcAngleLengthInRadians));

    arcToInner.setX((center - delta) * Math.cos(itemAngleInRadians));
    arcToInner.setY((center - delta) * Math.sin(itemAngleInRadians));
    arcToInner.setRadiusX(center);
    arcToInner.setRadiusY(center);
  }