View Javadoc
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.util;
18  
19  /** Holder for both sine and cosine values.
20   * <p>
21   * This class is a simple container, it does not provide any computational method.
22   * </p>
23   * @see FastMath#sinCos(double)
24   * @since 1.3
25   */
26  public class SinCos {
27  
28      /** Value of the sine. */
29      private final double sin;
30  
31      /** Value of the cosine. */
32      private final double cos;
33  
34      /** Simple constructor.
35       * @param sin value of the sine
36       * @param cos value of the cosine
37       */
38      SinCos(final double sin, final double cos) {
39          this.sin = sin;
40          this.cos = cos;
41      }
42  
43      /** Get the value of the sine.
44       * @return value of the sine
45       */
46      public double sin() {
47          return sin;
48      }
49  
50      /** Get the value of the cosine.
51       * @return value of the cosine
52       */
53      public double cos() {
54          return cos;
55      }
56  
57      /** Compute sine and cosine of angles sum.
58       * @param scAlpha \((\sin \alpha, \cos \alpha)\)
59       * @param scBeta \((\sin \beta, \cos \beta)\)
60       * @return \((\sin \alpha+\beta, \cos \alpha+\beta)\)
61       * @since 1.8
62       */
63      public static SinCos sum(final SinCos scAlpha, final SinCos scBeta) {
64          return new SinCos(MathArrays.linearCombination(scAlpha.sin, scBeta.cos,  scAlpha.cos, scBeta.sin),
65                            MathArrays.linearCombination(scAlpha.cos, scBeta.cos, -scAlpha.sin, scBeta.sin));
66      }
67  
68      /** Compute sine and cosine of angles difference.
69       * @param scAlpha \((\sin \alpha, \cos \alpha)\)
70       * @param scBeta \((\sin \beta, \cos \beta)\)
71       * @return \((\sin \alpha+\beta, \cos \alpha-\beta)\)
72       * @since 1.8
73       */
74      public static SinCos difference(final SinCos scAlpha, final SinCos scBeta) {
75          return new SinCos(MathArrays.linearCombination(scAlpha.sin, scBeta.cos, -scAlpha.cos, scBeta.sin),
76                            MathArrays.linearCombination(scAlpha.cos, scBeta.cos,  scAlpha.sin, scBeta.sin));
77      }
78  
79  }