java.lang.Math#cos ( )源码实例Demo

下面列出了java.lang.Math#cos ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Llunatic   文件: Exp.java
public Object exp(Object param)
	throws ParseException
{
	if (param instanceof Complex)
	{
	  	Complex z = (Complex) param;
	  	double x = z.re();
	  	double y = z.im();
	  	double mod = Math.exp(x);
		return new Complex(mod*Math.cos(y),mod*Math.sin(y));
	}
	else if (param instanceof Number) 
	{
		return new Double(Math.exp(((Number)param).doubleValue()));
	}

	throw new ParseException("Invalid parameter type");
}
 
源代码2 项目: GiantTrees   文件: Transformation.java
public Transformation rotaxisz(double delta, double rho) {
	// local rotation away from the local z-axis 
	// about an angle delta using an axis given by rho 
	// - used for splitting and random rotations
	delta = delta*Math.PI/180;
	rho = rho*Math.PI/180;
	
	double a = Math.cos(rho);
	double b = Math.sin(rho);
	double si = Math.sin(delta);
	double co = Math.cos(delta);
	
	Matrix rm = new Matrix((co+a*a*(1-co)),(b*a*(1-co)),(b*si),
			(a*b*(1-co)),(co+b*b*(1-co)),(-a*si),
			(-b*si),(a*si),(co));
	return new Transformation(matrix.prod(rm),vector);
}
 
源代码3 项目: GiantTrees   文件: Transformation.java
public Transformation rotaxis(double angle,Vector axis) {
	// rotation about an axis
	angle = angle*Math.PI/180;
	axis=axis.normalize();
	double a = axis.getX();
	double b = axis.getY();
	double c = axis.getZ();
	double si = Math.sin(angle);
	double co = Math.cos(angle);
	
	Matrix rm = new Matrix(
			(co+a*a*(1-co)),(-c*si+b*a*(1-co)),(b*si+c*a*(1-co)),
			(c*si+a*b*(1-co)),(co+b*b*(1-co)),(-a*si+c*b*(1-co)),
			(-b*si+a*c*(1-co)),(a*si+b*c*(1-co)),(co+c*c*(1-co)));
	return new Transformation(rm.prod(matrix),vector);
}
 
源代码4 项目: Llunatic   文件: Cosine.java
public Object cos(Object param)
	throws ParseException
{
	if (param instanceof Complex)
	{
		return ((Complex)param).cos();
	}
	else if (param instanceof Number)
	{
		return new Double(Math.cos(((Number)param).doubleValue()));
	}

	throw new ParseException("Invalid parameter type");
}
 
源代码5 项目: GiantTrees   文件: Transformation.java
public Transformation rotz(double angle) {
	// local rotation about z-axis
	angle = angle*Math.PI/180;
	Matrix rm = new Matrix(Math.cos(angle),-Math.sin(angle),0,
			Math.sin(angle),Math.cos(angle),0,
			0,0,1);
	return new Transformation(matrix.prod(rm),vector);
}
 
源代码6 项目: GiantTrees   文件: Transformation.java
public Transformation roty(double angle) {
	// local rotation about z-axis
	angle = angle*Math.PI/180;
	Matrix rm = new Matrix(Math.cos(angle),0,-Math.sin(angle),
			0,1,0,
			Math.sin(angle),0,Math.cos(angle));
	return new Transformation(matrix.prod(rm),vector);
}
 
源代码7 项目: GiantTrees   文件: Transformation.java
public Transformation rotx(double angle) {
	// local rotation about the x axis
	angle = angle*Math.PI/180;
	Matrix rm = new Matrix(1,0,0,
			0,Math.cos(angle),-Math.sin(angle),
			0,Math.sin(angle),Math.cos(angle));
	return new Transformation(matrix.prod(rm),vector);
}
 
源代码8 项目: GiantTrees   文件: Transformation.java
public Transformation rotxz(double delta, double rho) {
	// local rotation about the x and z axees - for the substems
	delta = delta*Math.PI/180;
	rho = rho*Math.PI/180;
	double sir = Math.sin(rho);
	double cor = Math.cos(rho);
	double sid = Math.sin(delta);
	double cod = Math.cos(delta);
	
	Matrix rm = new Matrix(cor,-sir*cod,sir*sid,
			sir,cor*cod,-cor*sid,
			0,sid,cod);
	return new Transformation(matrix.prod(rm),vector);
}
 
源代码9 项目: netcdf-java   文件: Bearing.java
/** @deprecated do not use */
@Deprecated
public static Bearing calculateBearing(Earth e, double lat1, double lon1, double lat2, double lon2, Bearing result) {
  if (result == null) {
    result = new Bearing();
  }

  if ((lat1 == lat2) && (lon1 == lon2)) {
    result.distance = 0;
    result.azimuth = 0;
    result.backazimuth = 0;
    return result;
  }

  double A = e.getMajor(); // Earth radius
  double F = e.getFlattening(); // Earth flattening value
  double R = 1.0 - F;

  double GLAT1 = DEGREES_TO_RADIANS * lat1;
  double GLAT2 = DEGREES_TO_RADIANS * lat2;
  double TU1 = R * Math.sin(GLAT1) / Math.cos(GLAT1);
  double TU2 = R * Math.sin(GLAT2) / Math.cos(GLAT2);
  double CU1 = 1. / Math.sqrt(TU1 * TU1 + 1.);
  double SU1 = CU1 * TU1;
  double CU2 = 1. / Math.sqrt(TU2 * TU2 + 1.);
  double S = CU1 * CU2;
  double BAZ = S * TU2;
  double FAZ = BAZ * TU1;
  double GLON1 = DEGREES_TO_RADIANS * lon1;
  double GLON2 = DEGREES_TO_RADIANS * lon2;
  double X = GLON2 - GLON1;
  double D, SX, CX, SY, CY, Y, SA, C2A, CZ, E, C;
  int loopCnt = 0;
  do {
    loopCnt++;
    // Check for an infinite loop
    if (loopCnt > 1000) {
      throw new IllegalArgumentException(
          "Too many iterations calculating bearing:" + lat1 + " " + lon1 + " " + lat2 + " " + lon2);
    }
    SX = Math.sin(X);
    CX = Math.cos(X);
    TU1 = CU2 * SX;
    TU2 = BAZ - SU1 * CU2 * CX;
    SY = Math.sqrt(TU1 * TU1 + TU2 * TU2);
    CY = S * CX + FAZ;
    Y = Math.atan2(SY, CY);
    SA = S * SX / SY;
    C2A = -SA * SA + 1.;
    CZ = FAZ + FAZ;
    if (C2A > 0.) {
      CZ = -CZ / C2A + CY;
    }
    E = CZ * CZ * 2. - 1.;
    C = ((-3. * C2A + 4.) * F + 4.) * C2A * F / 16.;
    D = X;
    X = ((E * CY * C + CZ) * SY * C + Y) * SA;
    X = (1. - C) * X * F + GLON2 - GLON1;
  } while (Math.abs(D - X) > EPS);

  FAZ = Math.atan2(TU1, TU2);
  BAZ = Math.atan2(CU1 * SX, BAZ * CX - SU1 * CU2) + Math.PI;
  X = Math.sqrt((1. / R / R - 1.) * C2A + 1.) + 1.;
  X = (X - 2.) / X;
  C = 1. - X;
  C = (X * X / 4. + 1.) / C;
  D = (0.375 * X * X - 1.) * X;
  X = E * CY;
  S = 1. - E - E;
  S = ((((SY * SY * 4. - 3.) * S * CZ * D / 6. - X) * D / 4. + CZ) * SY * D + Y) * C * A * R;

  result.distance = S / 1000.0; // meters to km
  result.azimuth = FAZ * RADIANS_TO_DEGREES; // radians to degrees

  if (result.azimuth < 0.0) {
    result.azimuth += 360.0; // reset azs from -180 to 180 to 0 to 360
  }

  result.backazimuth = BAZ * RADIANS_TO_DEGREES; // radians to degrees; already in 0 to 360 range

  return result;
}
 
源代码10 项目: KEEL   文件: Est_evol.java
private void Mutacion () {
	int n_hijo, i, j, nq, n1, n2;
	double z0, z1, x1, x2, si, co;

	for (n_hijo=0; n_hijo<Landa; n_hijo++) {
		/* Mutation of sigma */
		if (n_sigma==1)  /* if we use only a sigma, the sigma is adapted with Tau_1 */
			Hijos[n_hijo].Gene[tabla.n_variables] *= ValorNormal (Tau_1);
		else {
			z0 = ValorNormal (Tau_0);
			for (i=tabla.n_variables; i<tabla.n_variables + n_sigma; i++) {
				z1 = ValorNormal (Tau);
				Hijos[n_hijo].Gene[i] *= Math.exp (z1+z0);

				/* The standard desviation is Epsilon_sigma if it becomes 0 */
				if (Hijos[n_hijo].Gene[i]==0.0)
					Hijos[n_hijo].Gene[i] = Epsilon_sigma;
			}
		}  
      
		/* Mutation of alfa */
		for (i = tabla.n_variables + n_sigma; i<tabla.n_variables + n_sigma + n_alfa; i++) {
			z0 = ValorNormal (Beta);
			Hijos[n_hijo].Gene[i] += z0;

			/* Si el valor mutado se sale del intervalo [-i,i], se proyecta
			circularmente el valor a dicho intervalo */
			if (Math.abs(Hijos[n_hijo].Gene[i])>i)
				Hijos[n_hijo].Gene[i] -= 2 *i * signo (Hijos[n_hijo].Gene[i]);
		}

		/* Mutation of x */
  
		/* we calculate the uncorrelated vector of mutations */
		for (i=0; i<tabla.n_variables; i++)
			if (tabla.n_variables + i < tabla.n_variables + n_sigma)
				Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+i]);
			else /* if there aren't more tipical desviations we use the latest */
				Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+n_sigma-1]);      
   
		/* Correlation of the vector if we use the angles */  
		if (n_alfa!=0) {
			nq = n_alfa;
			for (j=nl_alfa; j<=nm_alfa; ++j) {
				n1 = tabla.n_variables - j;
				n2 = tabla.n_variables;
				for (i=1; i<=j; ++i) {
					x1 = Z[n1-1];
					x2 = Z[n2-1];
					si = Math.sin(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
					co = Math.cos(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
					Z[n2-1] = x1*si + x2*co;
					Z[n1-1] = x1*co - x2*si;
					--n2;
					--nq;
				}
			} 
		}
   
		/* Final mutation of X */ 
		for (i=0; i<tabla.n_variables; i++) {
			Hijos[n_hijo].Gene[i] += Z[i];	

			if (Hijos[n_hijo].Gene[i] < -(Math.PI/2.0))
				Hijos[n_hijo].Gene[i] = -(Math.PI/2.0) + 1E-10;
			if (Hijos[n_hijo].Gene[i] > (Math.PI/2.0))
				Hijos[n_hijo].Gene[i] = (Math.PI/2.0) - 1E-10;
		}
	}
}
 
源代码11 项目: KEEL   文件: Est_evol_M2TSK.java
private void Mutacion () {
	int n_hijo, i, j, nq, n1, n2;
	double z0, z1, x1, x2, si, co;

	for (n_hijo=0; n_hijo<Landa; n_hijo++) {
		/* Mutation of sigma */
		if (n_sigma==1)  /* if we use only a sigma, the sigma is adapted with Tau_1 */
			Hijos[n_hijo].Gene[tabla.n_variables] *= ValorNormal (Tau_1);
		else {
			z0 = ValorNormal (Tau_0);
			for (i=tabla.n_variables; i < tabla.n_variables + n_sigma; i++) {
				z1 = ValorNormal (Tau);
				Hijos[n_hijo].Gene[i] *= Math.exp (z1+z0);

				/* The standard desviation is Epsilon_sigma if it becomes 0 */
				if (Hijos[n_hijo].Gene[i]==0.0)
					Hijos[n_hijo].Gene[i] = Epsilon_sigma;
			}
		}

		/* Mutation of alfa */
		for (i = tabla.n_variables + n_sigma; i<tabla.n_variables + n_sigma + n_alfa; i++) {
			z0 = ValorNormal (Beta);
			Hijos[n_hijo].Gene[i] += z0;

			/* Si el valor mutado se sale del intervalo [-i,i], se proyecta
			circularmente el valor a dicho intervalo */
			if (Math.abs(Hijos[n_hijo].Gene[i])>i)  Hijos[n_hijo].Gene[i] -= 2.0 * PI * signo (Hijos[n_hijo].Gene[i]);
		}

		/* Mutation of x */

		/* we calculate the uncorrelated vector of mutations */
		for (i=0; i<tabla.n_variables; i++) {
			if (tabla.n_variables + i < tabla.n_variables + n_sigma)  Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+i]);
			else  Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+n_sigma-1]); /* if there aren't more tipical desviations we use the latest */
		}
				

		/* Correlation of the vector if we use the angles */
		if (n_alfa!=0) {
			nq = n_alfa;
			for (j=nl_alfa; j<=nm_alfa; ++j) {
				n1 = tabla.n_variables - j;
				n2 = tabla.n_variables;
				for (i=1; i<=j; ++i) {
					x1 = Z[n1-1];
					x2 = Z[n2-1];
					si = Math.sin(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
					co = Math.cos(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
					Z[n2-1] = x1*si + x2*co;
					Z[n1-1] = x1*co - x2*si;
					--n2;
					--nq;
				}
			}
		}

		/* Final mutation of X */
		for (i=0; i<tabla.n_variables; i++) {
			Hijos[n_hijo].Gene[i] += Z[i];

			if (Hijos[n_hijo].Gene[i] < (-1.0 * (PI/2.0)))  Hijos[n_hijo].Gene[i] = (-1.0 * (PI/2.0)) + 1E-10;
			if (Hijos[n_hijo].Gene[i] > (PI/2.0))  Hijos[n_hijo].Gene[i] = (PI/2.0) - 1E-10;
		}
	}
}
 
源代码12 项目: KEEL   文件: Est_mu_landa.java
private void Mutacion() {
  int n_hijo, i, j, nq, n1, n2;
  double z0, z1, x1, x2, si, co;

  for (n_hijo = 0; n_hijo < Landa; n_hijo++) {
    /* Mutation of sigma */
    if (n_sigma == 1)
        /* if we use only a sigma, the sigma is adapted with Tau_1 */
         {
      Hijos[n_hijo].Gene[tabla.n_variables] *= ValorNormal(Tau_1);
    }
    else {
      z0 = ValorNormal(Tau_0);
      for (i = tabla.n_variables; i < tabla.n_variables + n_sigma; i++) {
        z1 = ValorNormal(Tau);
        Hijos[n_hijo].Gene[i] *= Math.exp(z1 + z0);

        /* The standard desviation is Epsilon_sigma if it becomes 0 */
        if (Hijos[n_hijo].Gene[i] == 0.0) {
          Hijos[n_hijo].Gene[i] = Epsilon_sigma;
        }
      }
    }

    /* Mutation of alfa */
    for (i = tabla.n_variables + n_sigma;
         i < tabla.n_variables + n_sigma + n_alfa; i++) {
      z0 = ValorNormal(Beta);
      Hijos[n_hijo].Gene[i] += z0;

      /* Si el valor mutado se sale del intervalo [-i,i], se proyecta
           circularmente el valor a dicho intervalo */
      if (Math.abs(Hijos[n_hijo].Gene[i]) > i) {
        Hijos[n_hijo].Gene[i] -= 2 * PI * signo(Hijos[n_hijo].Gene[i]);
      }
    }

    /* Mutation of x */

    /* we calculate the uncorrelated vector of mutations */
    for (i = 0; i < tabla.n_variables; i++) {
      if (tabla.n_variables + i < tabla.n_variables + n_sigma) {
        Z[i] = ValorNormal(Hijos[n_hijo].Gene[tabla.n_variables + i]);
      }
      else
      /* if there aren't more tipical desviations we use the latest */
      {
        Z[i] = ValorNormal(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma - 1]);
      }
    }

    /* Correlation of the vector if we use the angles */
    if (n_alfa != 0) {
      nq = n_alfa;
      for (j = nl_alfa; j <= nm_alfa; ++j) {
        n1 = tabla.n_variables - j;
        n2 = tabla.n_variables;
        for (i = 1; i <= j; ++i) {
          x1 = Z[n1 - 1];
          x2 = Z[n2 - 1];
          si = Math.sin(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq -
                        1]);
          co = Math.cos(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq -
                        1]);
          Z[n2 - 1] = x1 * si + x2 * co;
          Z[n1 - 1] = x1 * co - x2 * si;
          --n2;
          --nq;
        }
      }
    }

    /* Final mutation of X */
    for (i = 0; i < tabla.n_variables; i++) {
      Hijos[n_hijo].Gene[i] += Z[i];

      if (Hijos[n_hijo].Gene[i] < - (PI / 2.0)) {
        Hijos[n_hijo].Gene[i] = - (PI / 2.0) + 1E-10;
      }
      if (Hijos[n_hijo].Gene[i] > (PI / 2.0)) {
        Hijos[n_hijo].Gene[i] = (PI / 2.0) - 1E-10;
      }
    }
  }
}
 
源代码13 项目: satstat   文件: UTM.java
public static String lat_lon_to_utm(double Lat, double Long, Context c) {

        double deg2rad = Math.PI / 180.0;
        double rad2deg = 180.0 / Math.PI;

        // Parameters for WGS-84
        double a = 6378137.0;
        double eccSquared = 0.00669438;
        double k0 = 0.9996;

        double LongTemp = (Long + 180) - (int) ((Long + 180) / 360) * 360 - 180;
        int ZoneNumber = ((int) (LongTemp + 180) / 6) + 1;

        double LatRad = Lat * deg2rad;
        double LongRad = LongTemp * deg2rad;

        if (Lat >= 56.0 && Lat < 64.0 && LongTemp >= 3.0 && LongTemp < 12.0) {
            ZoneNumber = 32;
        }

        // Special zones for Svalbard
        if (Lat >= 72.0 && Lat < 84.0)
            if (LongTemp >= 0.0 && LongTemp < 9.0)
                ZoneNumber = 31;
            else if (LongTemp >= 9.0 && LongTemp < 21.0) ZoneNumber = 33;
            else if (LongTemp >= 21.0 && LongTemp < 33.0) ZoneNumber = 35;
            else if (LongTemp >= 33.0 && LongTemp < 42.0) ZoneNumber = 37;

        double LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3;
        double LongOriginRad = LongOrigin * deg2rad;

        double eccPrimeSquared = (eccSquared) / (1 - eccSquared);
        double N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
        double T = Math.tan(LatRad) * Math.tan(LatRad);
        double C = eccPrimeSquared * Math.cos(LatRad) * Math.cos(LatRad);
        double A = Math.cos(LatRad) * (LongRad - LongOriginRad);

        double M = a * ((1 - eccSquared / 4
                - 3 * eccSquared * eccSquared / 64
                - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad
                - (3 * eccSquared / 8
                + 3 * eccSquared * eccSquared / 32
                + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(2 * LatRad)
                + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(4 * LatRad)
                - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.sin(6 * LatRad));

        double UTMEasting = (k0 * N * (A + (1 - T + C) * A * A * A / 6
                + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120)
                + 500000.0);

        double UTMNorthing = (k0 * (M + N * Math.tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24
                + (61
                - 58 * T
                + T * T
                + 600 * C
                - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720)));

        if (Lat > 84 || Lat < -80) {
            return (c.getString(R.string.utm_outside_latitude_range));
        } else {
            if (Lat < 0)
                UTMNorthing = UTMNorthing + 10000000.0;
            return (String.format("%d / %s / %,d / %,d", ZoneNumber, ((Lat > 0) ? "N" : "S"), Math.round(UTMEasting), Math.round(UTMNorthing)));
        }
    }
 
源代码14 项目: incubator-retired-mrql   文件: SystemFunctions.java
public static MR_double cos ( MR_double x ) { return new MR_double(Math.cos(x.get())); }