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
19 import org.hipparchus.util.FastMath;
20
21 /** Container for sexagesimal angle.
22 * <p>Instance of this class are guaranteed to be immutable.</p>
23 * @see GeodeticPoint
24 * @author Luc Maisonobe
25 * @since 13.0
26 */
27 public class SexagesimalAngle {
28
29 /** Sexagesimal base. */
30 private static final double SIXTY = 60.0;
31
32 /** Sign. */
33 private final int sign;
34
35 /** Degree part of the angle. */
36 private final int degree;
37
38 /** Arc-minute part of the angle. */
39 private final int arcMinute;
40
41 /** Arc-second part of the angle. */
42 private final double arcSecond;
43
44 /** Simple constructor.
45 * @param sign sign
46 * @param degree degree part of the angle
47 * @param arcMinute arc-minute part of the angle
48 * @param arcSecond arc-second part of the angle
49 */
50 public SexagesimalAngle(final int sign, final int degree, final int arcMinute, final double arcSecond) {
51 this.sign = sign;
52 this.degree = degree;
53 this.arcMinute = arcMinute;
54 this.arcSecond = arcSecond;
55 }
56
57 /** Simple constructor.
58 * @param angle angle in radians
59 */
60 public SexagesimalAngle(final double angle) {
61 this.sign = angle < 0 ? -1 : 1;
62 final double d = FastMath.toDegrees(FastMath.abs(angle));
63 this.degree = (int) FastMath.floor(d);
64 final double m = (d - degree) * SIXTY;
65 this.arcMinute = (int) FastMath.floor(m);
66 this.arcSecond = (m - arcMinute) * SIXTY;
67 }
68
69 /** Get sign.
70 * @return sign
71 */
72 public int getSign() {
73 return sign;
74 }
75
76 /** Get degree part of the angle.
77 * @return degree part of the angle
78 */
79 public int getDegree() {
80 return degree;
81 }
82
83 /** Get arc-minute part of the angle.
84 * @return arc-minute part of the angle
85 */
86 public int getArcMinute() {
87 return arcMinute;
88 }
89
90 /** Get arc-second part of the angle.
91 * @return arc-second part of the angle
92 */
93 public double getArcSecond() {
94 return arcSecond;
95 }
96
97 /** Get the corresponding angle in radians.
98 * @return angle in radians
99 */
100 public double getAngle() {
101 return FastMath.toRadians(sign * (degree + (arcMinute + arcSecond / SIXTY) / SIXTY));
102 }
103
104 }