JacobiEllipticBuilder.java

  1. /*
  2.  * Licensed to the Hipparchus project under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.hipparchus.special.elliptic.jacobi;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.complex.Complex;
  20. import org.hipparchus.complex.FieldComplex;

  21. /** Builder for algorithms compmuting Jacobi elliptic functions.
  22.  * <p>
  23.  * The Jacobi elliptic functions are related to elliptic integrals.
  24.  * </p>
  25.  * <p>
  26.  * There are different conventions to interpret the arguments of
  27.  * Jacobi elliptic functions. The first argument may be  the amplitude φ,
  28.  * but is more often the variable u (with sn(u) = sin(φ) and cn(u) = cos(φ)).
  29.  * The second argument  is either the modulus k or the parameter m with m = k².
  30.  * In Hipparchus, we adopted the convention to use u and m.
  31.  * </p>
  32.  * @since 2.0
  33.  */
  34. public class JacobiEllipticBuilder {

  35.     /** Threshold near 0 for using specialized algorithm. */
  36.     private static final double NEAR_ZERO = 1.0e-9;

  37.     /** Threshold near 1 for using specialized algorithm. */
  38.     private static final double NEAR_ONE = 1.0 - NEAR_ZERO;

  39.     /** Private constructor for utility class.
  40.      */
  41.     private JacobiEllipticBuilder() {
  42.         // nothing to do
  43.     }

  44.     /** Build an algorithm for computing Jacobi elliptic functions.
  45.      * @param m parameter of the Jacobi elliptic function
  46.      * @return selected algorithm
  47.      */
  48.     public static JacobiElliptic build(final double m) {
  49.         if (m < 0) {
  50.             return new NegativeParameter(m);
  51.         } else if (m > 1) {
  52.             return new BigParameter(m);
  53.         } else if (m < NEAR_ZERO) {
  54.             return new NearZeroParameter(m);
  55.         } else if (m > NEAR_ONE) {
  56.             return new NearOneParameter(m);
  57.         } else {
  58.             return new BoundedParameter(m);
  59.         }
  60.     }

  61.     /** Build an algorithm for computing Jacobi elliptic functions.
  62.      * @param m parameter of the Jacobi elliptic function
  63.      * @param <T> type of the field elements
  64.      * @return selected algorithm
  65.      */
  66.     public static <T extends CalculusFieldElement<T>> FieldJacobiElliptic<T> build(final T m) {
  67.         if (m.getReal() < 0) {
  68.             return new FieldNegativeParameter<>(m);
  69.         } else if (m.getReal() > 1) {
  70.             return new FieldBigParameter<>(m);
  71.         } else if (m.getReal() < NEAR_ZERO) {
  72.             return new FieldNearZeroParameter<>(m);
  73.         } else if (m.getReal() > NEAR_ONE) {
  74.             return new FieldNearOneParameter<>(m);
  75.         } else {
  76.             return new FieldBoundedParameter<>(m);
  77.         }
  78.     }

  79.     /** Build an algorithm for computing Jacobi elliptic functions.
  80.      * @param m parameter of the Jacobi elliptic function
  81.      * @return selected algorithm
  82.      */
  83.     public static FieldJacobiElliptic<Complex> build(final Complex m) {
  84.         return new ComplexParameter(m);
  85.     }

  86.     /** Build an algorithm for computing Jacobi elliptic functions.
  87.      * @param m parameter of the Jacobi elliptic function
  88.      * @param <T> type of the field elements
  89.      * @return selected algorithm
  90.      */
  91.     public static <T extends CalculusFieldElement<T>> FieldJacobiElliptic<FieldComplex<T>> build(final FieldComplex<T> m) {
  92.         return new FieldComplexParameter<>(m);
  93.     }

  94. }