SexagesimalAngle.java

  1. /* Copyright 2022-2025 Thales Alenia Space
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS 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.  *   http://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.orekit.bodies;

  18. import org.hipparchus.util.FastMath;

  19. /** Container for sexagesimal angle.
  20.  * <p>Instance of this class are guaranteed to be immutable.</p>
  21.  * @see GeodeticPoint
  22.  * @author Luc Maisonobe
  23.  * @since 13.0
  24.  */
  25. public class SexagesimalAngle {

  26.     /** Sexagesimal base. */
  27.     private static final double SIXTY = 60.0;

  28.     /** Sign. */
  29.     private final int sign;

  30.     /** Degree part of the angle. */
  31.     private final int degree;

  32.     /** Arc-minute part of the angle. */
  33.     private final int arcMinute;

  34.     /** Arc-second part of the angle. */
  35.     private final double arcSecond;

  36.     /** Simple constructor.
  37.      * @param sign sign
  38.      * @param degree degree part of the angle
  39.      * @param arcMinute arc-minute part of the angle
  40.      * @param arcSecond arc-second part of the angle
  41.      */
  42.     public SexagesimalAngle(final int sign, final int degree, final int arcMinute, final double arcSecond) {
  43.         this.sign      = sign;
  44.         this.degree    = degree;
  45.         this.arcMinute = arcMinute;
  46.         this.arcSecond = arcSecond;
  47.     }

  48.     /** Simple constructor.
  49.      * @param angle angle in radians
  50.      */
  51.     public SexagesimalAngle(final double angle) {
  52.         this.sign      = angle < 0 ? -1 : 1;
  53.         final double d = FastMath.toDegrees(FastMath.abs(angle));
  54.         this.degree    = (int) FastMath.floor(d);
  55.         final double m = (d - degree) * SIXTY;
  56.         this.arcMinute = (int) FastMath.floor(m);
  57.         this.arcSecond = (m - arcMinute) * SIXTY;
  58.     }

  59.     /** Get sign.
  60.      * @return sign
  61.      */
  62.     public int getSign() {
  63.         return sign;
  64.     }

  65.     /** Get degree part of the angle.
  66.      * @return degree part of the angle
  67.      */
  68.     public int getDegree() {
  69.         return degree;
  70.     }

  71.     /** Get arc-minute part of the angle.
  72.      * @return arc-minute part of the angle
  73.      */
  74.     public int getArcMinute() {
  75.         return arcMinute;
  76.     }

  77.     /** Get arc-second part of the angle.
  78.      * @return arc-second part of the angle
  79.      */
  80.     public double getArcSecond() {
  81.         return arcSecond;
  82.     }

  83.     /** Get the corresponding angle in radians.
  84.      * @return angle in radians
  85.      */
  86.     public double getAngle() {
  87.         return FastMath.toRadians(sign * (degree + (arcMinute + arcSecond / SIXTY) / SIXTY));
  88.     }

  89. }