Example usage for org.apache.commons.math.util MathUtils TWO_PI

List of usage examples for org.apache.commons.math.util MathUtils TWO_PI

Introduction

In this page you can find the example usage for org.apache.commons.math.util MathUtils TWO_PI.

Prototype

double TWO_PI

To view the source code for org.apache.commons.math.util MathUtils TWO_PI.

Click Source Link

Document

2 π.

Usage

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricFieldTest.java

/**
 * Test of getEx method, of class SquareUniformElectricField.
 *//*from   w w w. ja  va 2s .c o m*/
@Test
public void testGetEx() {
    System.out.println("testGetEx");
    SquareUniformElectricField instance = builder.build();

    // Inside the illumination area
    when(dummyRefractiveIndex.getN(10, 20, 0)).thenReturn(new Complex(1.0));
    Complex result = instance.getEx(10, 20, 0);
    assertEquals(1, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Inside the illumination area, different z-position
    Complex expResult = ComplexUtils.polar2Complex(orientation.getX(), MathUtils.TWO_PI / wavelength * 1.0);

    when(dummyRefractiveIndex.getN(10, 20, 1)).thenReturn(new Complex(1.0));
    result = instance.getEx(10, 20, 1);
    assertEquals(expResult.getReal(), result.getReal(), 0.0);
    assertEquals(expResult.getImaginary(), result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(-10, 20, 10)).thenReturn(new Complex(1.0));
    result = instance.getEx(-10, 20, 10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(30, 20, -10)).thenReturn(new Complex(1.0));
    result = instance.getEx(30, 20, -10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, -10, 100)).thenReturn(new Complex(1.0));
    result = instance.getEx(10, -10, 100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, 50, -100)).thenReturn(new Complex(1.0));
    result = instance.getEx(10, 50, -100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);
}

From source file:ch.epfl.leb.sass.models.illuminations.commands.internal.GenerateSquareUniformElectricFieldIT.java

/**
 * Test of generateElectricField method, of class GenerateSquareUniformElectricField.
 *///  w  w  w . j  a  v a2 s. c  om
@Test
public void testGenerateElectricField() {
    ElectricFieldCommand cmd = builder.build();
    ElectricField instance = cmd.generateElectricField();

    // Inside the illumination area
    Complex result = instance.getEx(10, 20, 0);
    assertEquals(1, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Inside the illumination area, different z-position
    Complex expResult = ComplexUtils.polar2Complex(orientation.getX(), MathUtils.TWO_PI / wavelength * 1.0);

    result = instance.getEx(10, 20, 1);
    assertEquals(expResult.getReal(), result.getReal(), 0.0);
    assertEquals(expResult.getImaginary(), result.getImaginary(), 0.0);

    // Outside the illumination area
    result = instance.getEx(-10, 20, 10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    result = instance.getEx(30, 20, -10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    result = instance.getEx(10, -10, 100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    result = instance.getEx(10, 50, -100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricField.java

/**
 * Returns the argument of the field's propagation phasor exp(j (k dot r)).
 * //  www.ja v a  2 s .  c o m
 * @param x The x-position within the sample.
 * @param y The y-position within the sample.
 * @param z The z-position within the sample.
 * @return The argument of the phasor.
 */
private Complex getArgument(double x, double y, double z) {
    // Compute the argument of the phasor.
    return refractiveIndex.getN(x, y, z).multiply(MathUtils.TWO_PI).divide(wavelength).multiply(z);
}

From source file:net.malariagen.gatk.math.SaddlePointExpansion.java

/**
 * Compute the PMF for a binomial distribution using the saddle point
 * expansion.//from w w  w . ja  v  a  2  s . c o m
 *
 * @param x the value at which the probability is evaluated.
 * @param n the number of trials.
 * @param p the probability of success.
 * @param q the probability of failure (1 - p).
 * @return log(p(x)).
 */
public static double logBinomialProbability(int x, int n, double p, double q) {
    double ret;
    if (x == 0) {
        if (p < 0.1) {
            ret = -getDeviancePart(n, n * q) - n * p;
        } else {
            ret = n * FastMath.log(q);
        }
    } else if (x == n) {
        if (q < 0.1) {
            ret = -getDeviancePart(n, n * p) - n * q;
        } else {
            ret = n * FastMath.log(p);
        }
    } else {
        ret = getStirlingError(n) - getStirlingError(x) - getStirlingError(n - x) - getDeviancePart(x, n * p)
                - getDeviancePart(n - x, n * q);
        double f = (MathUtils.TWO_PI * x * (n - x)) / n;
        ret = -0.5 * FastMath.log(f) + ret;
    }
    return ret;
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricFieldTest.java

/**
 * Test of getEx method, of class SquareUniformElectricField.
 *//*from w  w  w  .ja va2  s  . c o m*/
@Test
public void testGetExAbsorption() {
    System.out.println("testGetExAbsorption");
    SquareUniformElectricField instance = builder.build();

    // The imaginary part of the refractive index determines the absorption.
    Complex absRefractiveIndex = new Complex(1.0, 1.0);
    double z = 1.0;
    double arg = MathUtils.TWO_PI * z / wavelength;
    double mag = orientation.getX() * Math.exp(-arg * absRefractiveIndex.getImaginary());

    // Inside the illumination area, different z-position
    Complex expResult = ComplexUtils.polar2Complex(mag, arg * absRefractiveIndex.getReal());

    when(dummyRefractiveIndex.getN(10, 20, z)).thenReturn(absRefractiveIndex);
    Complex result = instance.getEx(10, 20, z);
    assertEquals(expResult.getReal(), result.getReal(), 0.0);
    assertEquals(expResult.getImaginary(), result.getImaginary(), 0.0);

}