Java Code Examples for java.lang.Math#tan()

The following examples show how to use java.lang.Math#tan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Adap.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
void Decodifica (double [] cromosoma) {
	int i, j;

	for (i=0; i<base_reglas.n_reglas; i++) {
		for (j=0; j<tabla.n_var_estado; j++) {
			base_reglas.BaseReglas[i].Ant[j].x0 = cromosoma[3*(i*tabla.n_var_estado+j)];
			base_reglas.BaseReglas[i].Ant[j].x1 = cromosoma[3*(i*tabla.n_var_estado+j)+1];
			base_reglas.BaseReglas[i].Ant[j].x2 = cromosoma[3*(i*tabla.n_var_estado+j)+1];
			base_reglas.BaseReglas[i].Ant[j].x3 = cromosoma[3*(i*tabla.n_var_estado+j)+2];
			base_reglas.BaseReglas[i].Ant[j].y = 1.0;
			base_reglas.BaseReglas[i].Ant[j].Nombre = "x" + (j+1);
			base_reglas.BaseReglas[i].Ant[j].Etiqueta = "E" + i + j;
			base_reglas.BaseReglas[i].Cons[j] = Math.tan (cromosoma[primer_gen_C2+i*(tabla.n_variables)+j]);
		}

		base_reglas.BaseReglas[i].Cons[j] = Math.tan (cromosoma[primer_gen_C2+i*(tabla.n_variables)+j]);
	}
}
 
Example 2
Source File: Adap_M2TSK.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
/** Inference process with the rule "Consecuentes" */
double Alfa_Error (double [] Consecuentes) {
	int i, j;
	double suma, salida;
	float aux;

	for (i=0, suma=0.0; i<n_ejemplos_positivos; i++) {
		salida = Math.tan (Consecuentes[tabla.n_var_estado]);
		for (j=0; j<tabla.n_var_estado; j++) {
			salida += Math.tan (Consecuentes[j]) * tabla.datos[indices_ep[i]].ejemplo[j];
		}

		suma += tabla.datos[indices_ep[i]].nivel_cubrimiento * Math.pow (tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado]-salida, 2.0);
	}

	return (suma);
}
 
Example 3
Source File: Adap_Tun.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
void Decodifica (double [] cromosoma) {
	int i, j;

	for (i=0; i<base_reglas.n_reglas; i++) {
		for (j=0; j<tabla.n_var_estado; j++) {
			base_reglas.BaseReglas[i].Ant[j].x0 = cromosoma[3*(i*tabla.n_var_estado+j)];
			base_reglas.BaseReglas[i].Ant[j].x1 = cromosoma[3*(i*tabla.n_var_estado+j)+1];
			base_reglas.BaseReglas[i].Ant[j].x2 = cromosoma[3*(i*tabla.n_var_estado+j)+1];
			base_reglas.BaseReglas[i].Ant[j].x3 = cromosoma[3*(i*tabla.n_var_estado+j)+2];
			base_reglas.BaseReglas[i].Ant[j].y = 1.0;
			base_reglas.BaseReglas[i].Ant[j].Nombre = "x" + (j+1);
			base_reglas.BaseReglas[i].Ant[j].Etiqueta = "E" + i + j;
			base_reglas.BaseReglas[i].Cons[j] = Math.tan (cromosoma[primer_gen_C2+i*(tabla.n_variables)+j]);
		}

		base_reglas.BaseReglas[i].Cons[j] = Math.tan (cromosoma[primer_gen_C2+i*(tabla.n_variables)+j]);
	}
}
 
Example 4
Source File: Adap.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
double Alfa_Error(double[] Consecuentes) {
  int i, j;
  double suma, salida;

  for (i = 0, suma = 0.0; i < n_ejemplos_positivos; i++) {
    /* Proceso de inferencia con una unica regla */
    /* inicializo la salida al valor b. Aplico la tangente para
        obtener el valor real porque dicho valor esta codificado
        con el angular coding */
    salida = Math.tan(Consecuentes[tabla.n_var_estado]);
    for (j = 0; j < tabla.n_var_estado; j++) {
      salida += Math.tan(Consecuentes[j]) *
          tabla.datos[indices_ep[i]].ejemplo[j];
    }

    suma += tabla.datos[indices_ep[i]].nivel_cubrimiento *
        Math.pow(tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado] -
                 salida, 2.0);
  }

  return (suma);
}
 
Example 5
Source File: Adap_Tun.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
void Decodifica(double[] cromosoma) {
  int i, j;

  for (i = 0; i < base_reglas.n_reglas; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      base_reglas.BaseReglas[i].Ant[j].x0 = cromosoma[3 * base_reglas.b_reglas[i][j]];
      base_reglas.BaseReglas[i].Ant[j].x1 = cromosoma[3 * base_reglas.b_reglas[i][j] + 1];
      base_reglas.BaseReglas[i].Ant[j].x2 = cromosoma[3 * base_reglas.b_reglas[i][j] + 1];
      base_reglas.BaseReglas[i].Ant[j].x3 = cromosoma[3 * base_reglas.b_reglas[i][j] + 2];
      base_reglas.BaseReglas[i].Ant[j].y = 1.0;
      base_reglas.BaseReglas[i].Ant[j].Nombre = "x" + (j + 1);
      base_reglas.BaseReglas[i].Ant[j].Etiqueta = "E" + i + j;
      base_reglas.BaseReglas[i].Cons[j] = Math.tan(cromosoma[primer_gen_C2 + i * (tabla.n_variables) + j]);
    }

    base_reglas.BaseReglas[i].Cons[j] = Math.tan(cromosoma[primer_gen_C2 + i * (tabla.n_variables) + j]);
  }
}
 
Example 6
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) 
{
    gl.glViewport(0, 0, width, height);

    float aspectRatio;
    float zNear =.1f;
    float zFar =1000;
    float fieldOfView = 30.0f/57.3f;                                                                       
    float size;
    	
    gl.glEnable(GL10.GL_NORMALIZE);
    	
    aspectRatio=(float)width/(float)height;                       
	    	
    gl.glMatrixMode(GL10.GL_PROJECTION);                                  
    	
    size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));   

    gl.glFrustumf(-size, size, -size /aspectRatio,                    
                           size /aspectRatio, zNear, zFar);
    	
    gl.glMatrixMode(GL10.GL_MODELVIEW);                              
}
 
Example 7
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) 
{
    gl.glViewport(0, 0, width, height);

    float aspectRatio;
    float zNear =.1f;
    float zFar =1000;
    float fieldOfView = 30.0f/57.3f;                                                                       
    float size;
    	
    gl.glEnable(GL10.GL_NORMALIZE);
    	
    aspectRatio=(float)width/(float)height;                       
	    	
    gl.glMatrixMode(GL10.GL_PROJECTION);                                  
    	
    size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));   

    gl.glFrustumf(-size, size, -size /aspectRatio,                    
                           size /aspectRatio, zNear, zFar);
    	
    gl.glMatrixMode(GL10.GL_MODELVIEW);                              
}
 
Example 8
Source File: Adap.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/** Inference process with the rule "Consecuentes" */
double Alfa_Error (double [] Consecuentes) {
	int i, j;
	double suma, salida;

	for (i=0, suma=0.0; i<n_ejemplos_positivos; i++) {
		salida = Math.tan (Consecuentes[tabla.n_var_estado]);
		for (j=0; j<tabla.n_var_estado; j++)
			salida += Math.tan (Consecuentes[j]) * tabla.datos[indices_ep[i]].ejemplo[j];

		suma += tabla.datos[indices_ep[i]].nivel_cubrimiento * Math.pow (tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado]-salida, 2.0);
	}

	return (suma);
}
 
Example 9
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);

     /*
      * Set our projection matrix. This doesn't have to be done
      * each time we draw, but usually a new projection needs to
      * be set when the viewport is resized.
      */
     
 	float aspectRatio;
	float zNear =.1f;
	float zFar =1000f;
	float fieldOfView = 30.0f/57.3f;
	float	size;
	
	gl.glEnable(GL10.GL_NORMALIZE);
	
	aspectRatio=(float)width/(float)height;				//h/w clamps the fov to the height, flipping it would make it relative to the width
	
	//Set the OpenGL projection matrix
	
	gl.glMatrixMode(GL10.GL_PROJECTION);
	
	size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));
	gl.glFrustumf(-size, size, -size/aspectRatio, size /aspectRatio, zNear, zFar);
	
	//Make the OpenGL modelview matrix the default
	
	gl.glMatrixMode(GL10.GL_MODELVIEW);
}
 
Example 10
Source File: SolarSystemRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);

     /*
      * Set our projection matrix. This doesn't have to be done
      * each time we draw, but usually a new projection needs to
      * be set when the viewport is resized.
      */
     
 	float aspectRatio;
	float zNear =.1f;
	float zFar =1000f;
	float fieldOfView = 30.0f/57.3f;
	float	size;
	
	gl.glEnable(GL10.GL_NORMALIZE);
	
	aspectRatio=(float)width/(float)height;				//h/w clamps the fov to the height, flipping it would make it relative to the width
	
	//Set the OpenGL projection matrix
	
	gl.glMatrixMode(GL10.GL_PROJECTION);
	
	size = zNear * (float)(Math.tan((double)(fieldOfView/2.0f)));
	gl.glFrustumf(-size, size, -size/aspectRatio, size /aspectRatio, zNear, zFar);
	
	//Make the OpenGL modelview matrix the default
	
	gl.glMatrixMode(GL10.GL_MODELVIEW);
}
 
Example 11
Source File: Tangent.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
public Object tan(Object param)
	throws ParseException
{
	if (param instanceof Complex)
		return ((Complex)param).tan();
	else if (param instanceof Number)
		return new Double(Math.tan(((Number)param).doubleValue()));

	throw new ParseException("Invalid parameter type");
}
 
Example 12
Source File: Est_evol.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/** Generates the initial population of fathers */
public void InicializaPadres () {
	int i, j, y, Mu_primer_grupo, pos_ep, total_mayor;
	double y_med, y_min, y_max, h_max, h_exigido, x;
	double imagen;

	/* we calculate the average, maximum and minimum high, and the matching with which a example is considerated in the initial population */
	y_med = y_min = y_max = tabla.datos[indices_ep[0]].ejemplo[tabla.n_var_estado];
	h_max = tabla.datos[indices_ep[0]].nivel_cubrimiento;

	for (i=1; i<fun_adap.n_ejemplos_positivos; i++) {
		if (tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado] > y_max)
			y_max = tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado] < y_min)
			y_min = tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado];
		
		y_med += tabla.datos[indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[indices_ep[i]].nivel_cubrimiento > h_max)
			h_max = tabla.datos[indices_ep[i]].nivel_cubrimiento;
	}

	y_med /= fun_adap.n_ejemplos_positivos;
	h_exigido = porcentaje_h * h_max;

	/* Inicialization of a individual with 'b' value same as the average high and with the 'a' values to 0 */
	for (j=0; j<tabla.n_var_estado; j++)  Padres[0].Gene[j] = 0;
	Padres[0].Gene[tabla.n_var_estado] = Math.atan(y_med);

	/* Inicialization of the porcentaje_Mu * Mu individuals with 'b' value equal to a random value in the rank [y_min,y_max] and with the 'a' values to 0 */
	Mu_primer_grupo = (int) (porcentaje_Mu * Mu + 1);
	for (i=1; i<Mu_primer_grupo; i++) {
		for (j=0; j<tabla.n_var_estado; j++)  Padres[i].Gene[j] = 0;
		Padres[i].Gene[tabla.n_var_estado] = Math.atan(Randomize.Randdouble (y_min,y_max));
	}

	/* Inicialization of the remaining individuals with the random 'a' values and with a the 'b' value for any to example is in the plane */
	for (i=Mu_primer_grupo; i<Mu; i++) {
		for (j=0; j<tabla.n_var_estado; j++) {
			if (Randomize.Rand ()<.5)  y = -1;
			else  y=1;

			x = Randomize.Rand ();
			Padres[i].Gene[j] = f(x,y);
		}
		
		/* we select randomly a example with a matching more high than "h_exigido" */
		for (total_mayor=pos_ep=0; pos_ep<fun_adap.n_ejemplos_positivos; pos_ep++)
			if (tabla.datos[indices_ep[pos_ep]].nivel_cubrimiento >= h_exigido)
				ind_mayor[total_mayor++] = pos_ep;
		
		if (total_mayor==0) {
			System.out.println("Error: The matching, with which a example is considerated in the initial population, isn't surmounted");
		}
		
		pos_ep = ind_mayor[Randomize.RandintClosed (0,total_mayor-1)];
		for (imagen=0.0,j=0; j<tabla.n_var_estado; j++)
			imagen += Math.tan (Padres[i].Gene[j]) * tabla.datos[indices_ep[pos_ep]].ejemplo[j];
		
		Padres[i].Gene[tabla.n_var_estado] = Math.atan(tabla.datos[indices_ep[pos_ep]].ejemplo[tabla.n_var_estado]-imagen);
	}


	/* Inicialization of the vector of tipical desviations */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables; j<tabla.n_variables+n_sigma; j++)  Padres[i].Gene[j] = Valor_Inicial_Sigma;

	/* Inicialization of the vector of angles: arcotangente of 1.0 */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables + n_sigma; j<tabla.n_variables+n_sigma+n_alfa; j++)  
			Padres[i].Gene[j] = Math.atan (1.0);
}
 
Example 13
Source File: Est_evol_M2TSK.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/** Generates the initial population of fathers */
public void InicializaPadres () {
	int i, j, y, Mu_primer_grupo, pos_ep, total_mayor;
	double y_med, y_min, y_max, h_max, h_exigido, x;
	double imagen;

	/* we calculate the average, maximum and minimum high, and the matching with which a example is considerated in the initial population */
	y_med = y_min = y_max = tabla.datos[fun_adap.indices_ep[0]].ejemplo[tabla.n_var_estado];
	h_max = tabla.datos[fun_adap.indices_ep[0]].nivel_cubrimiento;


	for (i=1; i<fun_adap.n_ejemplos_positivos; i++) {
		if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] > y_max)  y_max = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] < y_min)  y_min = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];

		y_med += tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
		if (tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento > h_max)  h_max = tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento;
	    
	}

	y_med /= fun_adap.n_ejemplos_positivos;
	h_exigido = porcentaje_h * h_max;



	/* Inicialization of a individual with 'b' value same as the average high and with the 'a' values to 0 */
	for (j=0; j<tabla.n_var_estado; j++)  Padres[0].Gene[j] = 0;
	Padres[0].Gene[tabla.n_var_estado] = Math.atan(y_med);

	/* Inicialization of the porcentaje_Mu * Mu individuals with 'b' value equal to a random value in the rank [y_min,y_max] and with the 'a' values to 0 */
	Mu_primer_grupo = (int) (porcentaje_Mu * Mu + 1);
	for (i=1; i<=Mu_primer_grupo; i++) {
		for (j=0; j<tabla.n_var_estado; j++)  Padres[i].Gene[j] = 0;
		Padres[i].Gene[tabla.n_var_estado] = Math.atan(Randomize.Randdouble (y_min,y_max));
	}

	/* Inicialization of the remaining individuals with the random 'a' values and with a the 'b' value for any to example is in the plane */
	for (i=Mu_primer_grupo+1; i<Mu; i++) {
		for (j=0; j<tabla.n_var_estado; j++) {
			if (Randomize.Rand () < 0.5)  y = -1;
			else  y=1;

			x = Randomize.Rand ();
			Padres[i].Gene[j] = f(x,y);
		}

		/* we select randomly a example with a matching more high than "h_exigido" */
		for (total_mayor=pos_ep=0; pos_ep<fun_adap.n_ejemplos_positivos; pos_ep++)
			if (tabla.datos[fun_adap.indices_ep[pos_ep]].nivel_cubrimiento >= h_exigido)  ind_mayor[total_mayor++] = pos_ep;

		if (total_mayor==0) {
			System.out.println("Error: The matching, with which a example is considerated in the initial population, isn't surmounted");
		}

		pos_ep = ind_mayor[Randomize.RandintClosed (0,total_mayor-1)];
		for (imagen=0.0,j=0; j<tabla.n_var_estado; j++)
			imagen += Math.tan (Padres[i].Gene[j]) * tabla.datos[fun_adap.indices_ep[pos_ep]].ejemplo[j];

		Padres[i].Gene[tabla.n_var_estado] = Math.atan(tabla.datos[fun_adap.indices_ep[pos_ep]].ejemplo[tabla.n_var_estado]-imagen);
	}


	/* Inicialization of the vector of tipical desviations */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables; j<tabla.n_variables+n_sigma; j++)  Padres[i].Gene[j] = Valor_Inicial_Sigma;

	/* Inicialization of the vector of angles: arcotangente of 1.0 */
	for (i=0; i<Mu; i++)
		for (j=tabla.n_variables + n_sigma; j<tabla.n_variables+n_sigma+n_alfa; j++)
			Padres[i].Gene[j] = Math.atan (1.0);
}
 
Example 14
Source File: Est_mu_landa.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/** Generates the initial population of fathers */
public void InicializaPadres() {
  int i, j, y, Mu_primer_grupo, pos_ep, total_mayor;
  double y_med, y_min, y_max, h_max, h_exigido, x;
  double imagen;

  /* we calculate the average, maximum and minimum high, and the matching with which a example is considerated in the initial population */
  y_med = y_min = y_max = tabla.datos[fun_adap.indices_ep[0]].ejemplo[tabla.
      n_var_estado];
  h_max = tabla.datos[fun_adap.indices_ep[0]].nivel_cubrimiento;

  for (i = 1; i < fun_adap.n_ejemplos_positivos; i++) {
    if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] > y_max) {
      y_max = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
    }
    if (tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado] < y_min) {
      y_min = tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
    }

    y_med += tabla.datos[fun_adap.indices_ep[i]].ejemplo[tabla.n_var_estado];
    if (tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento > h_max) {
      h_max = tabla.datos[fun_adap.indices_ep[i]].nivel_cubrimiento;
    }
  }

  if (fun_adap.n_ejemplos_positivos > 0) {
    y_med /= fun_adap.n_ejemplos_positivos;
  }
  else {
    y_med = Double.MAX_VALUE;
  }
  h_exigido = porcentaje_h * h_max;

  /* Inicialization of a individual with 'b' value same as the average high and with the 'a' values to 0 */
  for (j = 0; j < tabla.n_var_estado; j++) {
    Padres[0].Gene[j] = 0;
  }
  Padres[0].Gene[tabla.n_var_estado] = Math.atan(y_med);

  /* Inicialization of the porcentaje_Mu * Mu individuals with 'b' value equal to a random value in the rank [y_min,y_max] and with the 'a' values to 0 */
  Mu_primer_grupo = (int) (porcentaje_Mu * Mu + 1);
  for (i = 1; i <= Mu_primer_grupo; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      Padres[i].Gene[j] = 0;
    }
    Padres[i].Gene[tabla.n_var_estado] = Math.atan(Randomize.Randdouble(y_min,
        y_max));
  }

  /* Inicialization of the remaining individuals with the random 'a' values and with a the 'b' value for any to example is in the plane */
  for (i = Mu_primer_grupo + 1; i < Mu; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      if (Randomize.Rand() < 0.5) {
        y = -1;
      }
      else {
        y = 1;
      }

      x = Randomize.Rand();
      Padres[i].Gene[j] = f(x, y);
    }

    /* we select randomly a example with a matching more high than "h_exigido" */
    for (total_mayor = pos_ep = 0; pos_ep < fun_adap.n_ejemplos_positivos;
         pos_ep++) {
      if (tabla.datos[fun_adap.indices_ep[pos_ep]].nivel_cubrimiento >= h_exigido) {
        ind_mayor[total_mayor++] = pos_ep;
      }
    }

    if (total_mayor == 0) {
      System.out.println("Error: The matching, with which a example is considerated in the initial population, isn't surmounted");
    }

    pos_ep = ind_mayor[Randomize.RandintClosed(0, total_mayor - 1)];
    for (imagen = 0.0, j = 0; j < tabla.n_var_estado; j++) {
      imagen += Math.tan(Padres[i].Gene[j]) *
          tabla.datos[fun_adap.indices_ep[pos_ep]].ejemplo[j];
    }

    Padres[i].Gene[tabla.n_var_estado] = Math.atan(tabla.datos[fun_adap.indices_ep[
        pos_ep]].ejemplo[tabla.n_var_estado] - imagen);
  }

  /* Inicialization of the vector of tipical desviations */
  for (i = 0; i < Mu; i++) {
    for (j = tabla.n_variables; j < tabla.n_variables + n_sigma; j++) {
      Padres[i].Gene[j] = Valor_Inicial_Sigma;
    }
  }

  /* Inicialization of the vector of angles: arcotangente of 1.0 */
  for (i = 0; i < Mu; i++) {
    for (j = tabla.n_variables + n_sigma;
         j < tabla.n_variables + n_sigma + n_alfa; j++) {
      Padres[i].Gene[j] = Math.atan(1.0);
    }
  }
}
 
Example 15
Source File: UTM.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
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)));
        }
    }
 
Example 16
Source File: SystemFunctions.java    From incubator-retired-mrql with Apache License 2.0 votes vote down vote up
public static MR_double tan ( MR_double x ) { return new MR_double(Math.tan(x.get())); }