Java Code Examples for org.apache.commons.math.util.FastMath#sin()
The following examples show how to use
org.apache.commons.math.util.FastMath#sin() .
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: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public Side side(final Hyperplane<Euclidean2D> hyperplane) { final Line thisLine = (Line) getHyperplane(); final Line otherLine = (Line) hyperplane; final Vector2D crossing = thisLine.intersection(otherLine); if (crossing == null) { // the lines are parallel, final double global = otherLine.getOffset(thisLine); return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER); } // the lines do intersect final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0; final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing); return getRemainingRegion().side(new OrientedPoint(x, direct)); }
Example 2
Source File: SubLine.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public Side side(final Hyperplane<Euclidean2D> hyperplane) { final Line thisLine = (Line) getHyperplane(); final Line otherLine = (Line) hyperplane; final Vector2D crossing = thisLine.intersection(otherLine); if (crossing == null) { // the lines are parallel, final double global = otherLine.getOffset(thisLine); return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER); } // the lines do intersect final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0; final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing); return getRemainingRegion().side(new OrientedPoint(x, direct)); }
Example 3
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Estimate a first guess of the phase. */ private void guessPhi() { // initialize the means double fcMean = 0; double fsMean = 0; double currentX = observations[0].getX(); double currentY = observations[0].getY(); for (int i = 1; i < observations.length; ++i) { // one step forward final double previousX = currentX; final double previousY = currentY; currentX = observations[i].getX(); currentY = observations[i].getY(); final double currentYPrime = (currentY - previousY) / (currentX - previousX); double omegaX = omega * currentX; double cosine = FastMath.cos(omegaX); double sine = FastMath.sin(omegaX); fcMean += omega * currentY * cosine - currentYPrime * sine; fsMean += omega * currentY * sine + currentYPrime * cosine; } phi = FastMath.atan2(-fsMean, fcMean); }
Example 4
Source File: 1_Complex.java From SimFix with GNU General Public License v2.0 | 5 votes |
/** * <p>Computes the n-th roots of this complex number. * </p> * <p>The nth roots are defined by the formula: <pre> * <code> z<sub>k</sub> = abs<sup> 1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))</code></pre> * for <i><code>k=0, 1, ..., n-1</code></i>, where <code>abs</code> and <code>phi</code> are * respectively the {@link #abs() modulus} and {@link #getArgument() argument} of this complex number. * </p> * <p>If one or both parts of this complex number is NaN, a list with just one element, * {@link #NaN} is returned.</p> * <p>if neither part is NaN, but at least one part is infinite, the result is a one-element * list containing {@link #INF}.</p> * * @param n degree of root * @return List<Complex> all nth roots of this complex number * @throws IllegalArgumentException if parameter n is less than or equal to 0 * @since 2.0 */ public List<Complex> nthRoot(int n) throws IllegalArgumentException { if (n <= 0) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument()/n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 5
Source File: arja8_eigth_t.java From coming with MIT License | 5 votes |
/** * <p>Computes the n-th roots of this complex number. * </p> * <p>The nth roots are defined by the formula: <pre> * <code> z<sub>k</sub> = abs<sup> 1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))</code></pre> * for <i><code>k=0, 1, ..., n-1</code></i>, where <code>abs</code> and <code>phi</code> are * respectively the {@link #abs() modulus} and {@link #getArgument() argument} of this complex number. * </p> * <p>If one or both parts of this complex number is NaN, a list with just one element, * {@link #NaN} is returned.</p> * <p>if neither part is NaN, but at least one part is infinite, the result is a one-element * list containing {@link #INF}.</p> * * @param n degree of root * @return List<Complex> all nth roots of this complex number * @throws IllegalArgumentException if parameter n is less than or equal to 0 * @since 2.0 */ public List<Complex> nthRoot(int n) throws IllegalArgumentException { if (n <= 0) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument()/n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 6
Source File: TestProblem4.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public double[] computeTheoreticalState(double t) { double sin = FastMath.sin(t + a); double cos = FastMath.cos(t + a); y[0] = FastMath.abs(sin); y[1] = (sin >= 0) ? cos : -cos; return y; }
Example 7
Source File: Complex_s.java From coming with MIT License | 5 votes |
/** * Computes the n-th roots of this complex number. * The nth roots are defined by the formula: * <pre> * <code> * z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n)) * </code> * </pre> * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi} * are respectively the {@link #abs() modulus} and * {@link #getArgument() argument} of this complex number. * <br/> * If one or both parts of this complex number is NaN, a list with just * one element, {@link #NaN} is returned. * if neither part is NaN, but at least one part is infinite, the result * is a one-element list containing {@link #INF}. * * @param n Degree of root. * @return a List<Complex> of all {@code n}-th roots of {@code this}. * @throws NotPositiveException if {@code n <= 0}. * @since 2.0 */ public List<Complex> nthRoot(int n) { if (n <= 0) { throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } final List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument() / n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 8
Source File: Complex_t.java From coming with MIT License | 5 votes |
/** * <p> * Computes the n-th roots of this complex number. * </p> * <p> * The nth roots are defined by the formula: * * <pre> * <code> z<sub>k</sub> = abs<sup> 1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))</code> * </pre> * * for <i><code>k=0, 1, ..., n-1</code></i>, where <code>abs</code> and * <code>phi</code> are respectively the {@link #abs() modulus} and * {@link #getArgument() argument} of this complex number. * </p> * <p> * If one or both parts of this complex number is NaN, a list with just one * element, {@link #NaN} is returned. * </p> * <p> * if neither part is NaN, but at least one part is infinite, the result is a * one-element list containing {@link #INF}. * </p> * * @param n degree of root * @return List<Complex> all nth roots of this complex number * @throws IllegalArgumentException if parameter n is less than or equal to 0 * @since 2.0 */ public List<Complex> nthRoot(int n) throws IllegalArgumentException { if (n <= 0) { throw MathRuntimeException .createIllegalArgumentException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument() / n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 9
Source File: Cardumen_00218_s.java From coming with MIT License | 5 votes |
/** * Computes the n-th roots of this complex number. * The nth roots are defined by the formula: * <pre> * <code> * z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n)) * </code> * </pre> * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi} * are respectively the {@link #abs() modulus} and * {@link #getArgument() argument} of this complex number. * <br/> * If one or both parts of this complex number is NaN, a list with just * one element, {@link #NaN} is returned. * if neither part is NaN, but at least one part is infinite, the result * is a one-element list containing {@link #INF}. * * @param n Degree of root. * @return a List<Complex> of all {@code n}-th roots of {@code this}. * @throws NotPositiveException if {@code n <= 0}. * @since 2.0 */ public List<Complex> nthRoot(int n) { if (n <= 0) { throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } final List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument() / n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 10
Source File: Math_47_Complex_s.java From coming with MIT License | 5 votes |
/** * Computes the n-th roots of this complex number. * The nth roots are defined by the formula: * <pre> * <code> * z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n)) * </code> * </pre> * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi} * are respectively the {@link #abs() modulus} and * {@link #getArgument() argument} of this complex number. * <br/> * If one or both parts of this complex number is NaN, a list with just * one element, {@link #NaN} is returned. * if neither part is NaN, but at least one part is infinite, the result * is a one-element list containing {@link #INF}. * * @param n Degree of root. * @return a List<Complex> of all {@code n}-th roots of {@code this}. * @throws NotPositiveException if {@code n <= 0}. * @since 2.0 */ public List<Complex> nthRoot(int n) { if (n <= 0) { throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } final List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument() / n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 11
Source File: TestProblem4.java From astor with GNU General Public License v2.0 | 5 votes |
/** Simple constructor. */ public TestProblem4() { super(); a = 1.2; double[] y0 = { FastMath.sin(a), FastMath.cos(a) }; setInitialConditions(0.0, y0); setFinalConditions(15); double[] errorScale = { 1.0, 0.0 }; setErrorScale(errorScale); y = new double[y0.length]; }
Example 12
Source File: Cardumen_0044_t.java From coming with MIT License | 5 votes |
/** * Computes the n-th roots of this complex number. * The nth roots are defined by the formula: * <pre> * <code> * z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n)) * </code> * </pre> * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi} * are respectively the {@link #abs() modulus} and * {@link #getArgument() argument} of this complex number. * <br/> * If one or both parts of this complex number is NaN, a list with just * one element, {@link #NaN} is returned. * if neither part is NaN, but at least one part is infinite, the result * is a one-element list containing {@link #INF}. * * @param n Degree of root. * @return a List<Complex> of all {@code n}-th roots of {@code this}. * @throws NotPositiveException if {@code n <= 0}. * @since 2.0 */ public List<Complex> nthRoot(int n) { if (n <= 0) { throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } final List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument() / n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 13
Source File: SubLine.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public SplitSubHyperplane<Euclidean2D> split(final Hyperplane<Euclidean2D> hyperplane) { final Line thisLine = (Line) getHyperplane(); final Line otherLine = (Line) hyperplane; final Vector2D crossing = thisLine.intersection(otherLine); if (crossing == null) { // the lines are parallel final double global = otherLine.getOffset(thisLine); return (global < -1.0e-10) ? new SplitSubHyperplane<Euclidean2D>(null, this) : new SplitSubHyperplane<Euclidean2D>(this, null); } // the lines do intersect final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0; final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing); final SubHyperplane<Euclidean1D> subPlus = new OrientedPoint(x, !direct).wholeHyperplane(); final SubHyperplane<Euclidean1D> subMinus = new OrientedPoint(x, direct).wholeHyperplane(); final BSPTree<Euclidean1D> splitTree = getRemainingRegion().getTree(false).split(subMinus); final BSPTree<Euclidean1D> plusTree = getRemainingRegion().isEmpty(splitTree.getPlus()) ? new BSPTree<Euclidean1D>(Boolean.FALSE) : new BSPTree<Euclidean1D>(subPlus, new BSPTree<Euclidean1D>(Boolean.FALSE), splitTree.getPlus(), null); final BSPTree<Euclidean1D> minusTree = getRemainingRegion().isEmpty(splitTree.getMinus()) ? new BSPTree<Euclidean1D>(Boolean.FALSE) : new BSPTree<Euclidean1D>(subMinus, new BSPTree<Euclidean1D>(Boolean.FALSE), splitTree.getMinus(), null); return new SplitSubHyperplane<Euclidean2D>(new SubLine(thisLine.copySelf(), new IntervalsSet(plusTree)), new SubLine(thisLine.copySelf(), new IntervalsSet(minusTree))); }
Example 14
Source File: JGenProg2017_0028_s.java From coming with MIT License | 5 votes |
/** * <p>Computes the n-th roots of this complex number. * </p> * <p>The nth roots are defined by the formula: <pre> * <code> z<sub>k</sub> = abs<sup> 1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))</code></pre> * for <i><code>k=0, 1, ..., n-1</code></i>, where <code>abs</code> and <code>phi</code> are * respectively the {@link #abs() modulus} and {@link #getArgument() argument} of this complex number. * </p> * <p>If one or both parts of this complex number is NaN, a list with just one element, * {@link #NaN} is returned.</p> * <p>if neither part is NaN, but at least one part is infinite, the result is a one-element * list containing {@link #INF}.</p> * * @param n degree of root * @return List<Complex> all nth roots of this complex number * @throws IllegalArgumentException if parameter n is less than or equal to 0 * @since 2.0 */ public List<Complex> nthRoot(int n) throws IllegalArgumentException { if (n <= 0) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N, n); } List<Complex> result = new ArrayList<Complex>(); if (isNaN) { result.add(NaN); return result; } if (isInfinite()) { result.add(INF); return result; } // nth root of abs -- faster / more accurate to use a solver here? final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); // Compute nth roots of complex number with k = 0, 1, ... n-1 final double nthPhi = getArgument()/n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { // inner part final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice; } return result; }
Example 15
Source File: UnivariateRealPeriodicInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testSine() { final int n = 30; final double[] xval = new double[n]; final double[] yval = new double[n]; final double period = 12.3; final double offset = 45.67; double delta = 0; for (int i = 0; i < n; i++) { delta += rng.nextDouble() * period / n; xval[i] = offset + delta; yval[i] = FastMath.sin(xval[i]); } final UnivariateRealInterpolator inter = new LinearInterpolator(); final UnivariateRealFunction f = inter.interpolate(xval, yval); final UnivariateRealInterpolator interP = new UnivariateRealPeriodicInterpolator(new LinearInterpolator(), period, 1); final UnivariateRealFunction fP = interP.interpolate(xval, yval); // Comparing with original interpolation algorithm. final double xMin = xval[0]; final double xMax = xval[n - 1]; for (int i = 0; i < n; i++) { final double x = xMin + (xMax - xMin) * rng.nextDouble(); final double y = f.value(x); final double yP = fP.value(x); Assert.assertEquals("x=" + x, y, yP, Math.ulp(1d)); } // Test interpolation outside the primary interval. for (int i = 0; i < n; i++) { final double xIn = offset + rng.nextDouble() * period; final double xOut = xIn + rng.nextInt(123456789) * period; final double yIn = fP.value(xIn); final double yOut = fP.value(xOut); Assert.assertEquals(yIn, yOut, 1e-7); } }
Example 16
Source File: Math_52_Rotation_t.java From coming with MIT License | 4 votes |
/** Build a rotation from an axis and an angle. * <p>We use the convention that angles are oriented according to * the effect of the rotation on vectors around the axis. That means * that if (i, j, k) is a direct frame and if we first provide +k as * the axis and π/2 as the angle to this constructor, and then * {@link #applyTo(Vector3D) apply} the instance to +i, we will get * +j.</p> * <p>Another way to represent our convention is to say that a rotation * of angle θ about the unit vector (x, y, z) is the same as the * rotation build from quaternion components { cos(-θ/2), * x * sin(-θ/2), y * sin(-θ/2), z * sin(-θ/2) }. * Note the minus sign on the angle!</p> * <p>On the one hand this convention is consistent with a vectorial * perspective (moving vectors in fixed frames), on the other hand it * is different from conventions with a frame perspective (fixed vectors * viewed from different frames) like the ones used for example in spacecraft * attitude community or in the graphics community.</p> * @param axis axis around which to rotate * @param angle rotation angle. * @exception ArithmeticException if the axis norm is zero */ public Rotation(Vector3D axis, double angle) { double norm = axis.getNorm(); if (norm == 0) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_AXIS); } double halfAngle = -0.5 * angle; double coeff = FastMath.sin(halfAngle) / norm; q0 = FastMath.cos (halfAngle); q1 = coeff * axis.getX(); q2 = coeff * axis.getY(); q3 = coeff * axis.getZ(); }
Example 17
Source File: FastCosineTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the FCT algorithm (including inverse). * * @param f the real data array to be transformed * @return the real transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected double[] fct(double f[]) throws IllegalArgumentException { final double transformed[] = new double[f.length]; final int n = f.length - 1; if (!FastFourierTransformer.isPowerOf2(n)) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE, f.length); } if (n == 1) { // trivial case transformed[0] = 0.5 * (f[0] + f[1]); transformed[1] = 0.5 * (f[0] - f[1]); return transformed; } // construct a new array and perform FFT on it final double[] x = new double[n]; x[0] = 0.5 * (f[0] + f[n]); x[n >> 1] = f[n >> 1]; double t1 = 0.5 * (f[0] - f[n]); // temporary variable for transformed[1] for (int i = 1; i < (n >> 1); i++) { final double a = 0.5 * (f[i] + f[n-i]); final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n-i]); final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n-i]); x[i] = a - b; x[n-i] = a + b; t1 += c; } FastFourierTransformer transformer = new FastFourierTransformer(); Complex y[] = transformer.transform(x); // reconstruct the FCT result for the original array transformed[0] = y[0].getReal(); transformed[1] = t1; for (int i = 1; i < (n >> 1); i++) { transformed[2 * i] = y[i].getReal(); transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary(); } transformed[n] = y[n >> 1].getReal(); return transformed; }
Example 18
Source File: Sinc.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double value(double x) { return FastMath.abs(x) < 1e-9 ? 1 : FastMath.sin(x) / x; }
Example 19
Source File: AIAction.java From gameserver with Apache License 2.0 | 4 votes |
/** * Use the (hitx,hity) point and given angle to calculate the power needed. * * @param angle * @param hitx * @param hity * @return */ public static final int calculatePower(int angle, int hitx, int hity, int wind) { //Caculate the running time //0.055 //double K = GameDataManager.getInstance().getGameDataAsDouble(GameDataKey.BATTLE_ATTACK_K, 0.059081); //double F = GameDataManager.getInstance().getGameDataAsDouble(GameDataKey.BATTLE_ATTACK_F, 0.075); //int g = GameDataManager.getInstance().getGameDataAsInt(GameDataKey.BATTLE_ATTACK_G, 760); double rad = angle/180.0*Math.PI; double sin = FastMath.sin(rad); double cos = FastMath.cos(rad); double tx = hitx/3; int ty = 0; double a = sin; double b = -ty; double c = 0; double d = Math.abs(tx*tx / (2*cos)); int power = (int)MathUtil.solveCubicEquation(a, b, c, d); logger.debug("a:{},b:{},c:{},d:{},wind:{},power:{}", new Object[]{a, b, c, d,wind, power}); if ( power < 0 ) { power = -power; } if ( power > 100 ) { power = 100; } /** * wind < 0 风向向右侧 * wind > 0 风向向左侧 */ if ( wind < 0 && angle > 90 ) { power += -wind * 2 + 5; } else if ( wind < 0 && angle < 90 ) { /** * 村口小桥顺风情况下计算的力度偏小,所以 * 这里去掉了风力的数值 * 2013-01-14 */ //power -= -wind * 2 - 5; } else if ( wind > 0 && angle < 90 ) { power += wind * 2 + 5; } else if ( wind > 0 && angle > 90 ) { power -= wind * 2 - 5; } return (int)power; }
Example 20
Source File: ComplexUtils.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Creates a complex number from the given polar representation. * <p> * The value returned is <code>r·e<sup>i·theta</sup></code>, * computed as <code>r·cos(theta) + r·sin(theta)i</code></p> * <p> * If either <code>r</code> or <code>theta</code> is NaN, or * <code>theta</code> is infinite, {@link Complex#NaN} is returned.</p> * <p> * If <code>r</code> is infinite and <code>theta</code> is finite, * infinite or NaN values may be returned in parts of the result, following * the rules for double arithmetic.<pre> * Examples: * <code> * polar2Complex(INFINITY, π/4) = INFINITY + INFINITY i * polar2Complex(INFINITY, 0) = INFINITY + NaN i * polar2Complex(INFINITY, -π/4) = INFINITY - INFINITY i * polar2Complex(INFINITY, 5π/4) = -INFINITY - INFINITY i </code></pre></p> * * @param r the modulus of the complex number to create * @param theta the argument of the complex number to create * @return <code>r·e<sup>i·theta</sup></code> * @throws IllegalArgumentException if r is negative * @since 1.1 */ public static Complex polar2Complex(double r, double theta) { if (r < 0) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.NEGATIVE_COMPLEX_MODULE, r); } return new Complex(r * FastMath.cos(theta), r * FastMath.sin(theta)); }