1 /* Copyright 2011-2012 Space Applications Services
2 * Licensed to CS Communication & Systèmes (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.models.earth;
18
19 import java.io.Serial;
20 import java.io.Serializable;
21 import java.text.DecimalFormat;
22 import java.text.NumberFormat;
23
24 import org.hipparchus.geometry.euclidean.threed.Vector3D;
25 import org.hipparchus.util.FastMath;
26 import org.orekit.utils.units.UnitsConverter;
27
28 /** Contains the elements to represent a magnetic field at a single point.
29 * @author Thomas Neidhart
30 */
31 public class GeoMagneticElements implements Serializable {
32
33 /** Serializable UID. */
34 @Serial
35 private static final long serialVersionUID = 1881493738280586855L;
36
37 /** The magnetic field vector (East=X, North=Y, Nadir=Z). */
38 private final Vector3D b;
39
40 /** The magnetic inclination in radians. */
41 private final double inclination;
42
43 /** The magnetic declination in radians. */
44 private final double declination;
45
46 /** The magnetic total intensity, in Teslas. */
47 private final double totalIntensity;
48
49 /** The magnetic horizontal intensity, in Teslas. */
50 private final double horizontalIntensity;
51
52 /** Construct a new element with the given field vector. The other elements
53 * of the magnetic field are calculated from the field vector.
54 * @param b the magnetic field vector
55 */
56 public GeoMagneticElements(final Vector3D b) {
57 this.b = new Vector3D(UnitsConverter.NANO_TESLAS_TO_TESLAS.getFrom().getScale(), b);
58
59 final double intensityNanoTesla = FastMath.hypot(b.getX(), b.getY());
60 horizontalIntensity = UnitsConverter.NANO_TESLAS_TO_TESLAS.convert(intensityNanoTesla);
61 totalIntensity = UnitsConverter.NANO_TESLAS_TO_TESLAS.convert(b.getNorm());
62 declination = FastMath.atan2(b.getY(), b.getX());
63 inclination = FastMath.atan2(b.getZ(), intensityNanoTesla);
64 }
65
66 /** Returns the magnetic field vector in Tesla.
67 * @return the magnetic field vector in Tesla
68 */
69 public Vector3D getFieldVector() {
70 return b;
71 }
72
73 /** Returns the inclination of the magnetic field in radians.
74 * @return the inclination (dip) in radians
75 */
76 public double getInclination() {
77 return inclination;
78 }
79
80 /** Returns the declination of the magnetic field in radians.
81 * @return the declination (dec) in radians
82 */
83 public double getDeclination() {
84 return declination;
85 }
86
87 /** Returns the total intensity of the magnetic field (= norm of the field vector).
88 * @return the total intensity in Tesla
89 */
90 public double getTotalIntensity() {
91 return totalIntensity;
92 }
93
94 /** Returns the horizontal intensity of the magnetic field (= norm of the
95 * vector in the plane spanned by the x/y components of the field vector).
96 * @return the horizontal intensity in Tesla
97 */
98 public double getHorizontalIntensity() {
99 return horizontalIntensity;
100 }
101
102 @Override
103 public String toString() {
104 final NumberFormat f = NumberFormat.getInstance();
105 final DecimalFormat d = new DecimalFormat("0.######E0");
106 final StringBuilder sb = new StringBuilder();
107 sb.append("MagneticField[");
108 sb.append("B=");
109 sb.append(b.toString(d));
110 sb.append(",H=");
111 sb.append(d.format(getHorizontalIntensity()));
112 sb.append(",F=");
113 sb.append(d.format(getTotalIntensity()));
114 sb.append(",I=");
115 sb.append(f.format(getInclination()));
116 sb.append(",D=");
117 sb.append(f.format(getDeclination()));
118 sb.append("]");
119 return sb.toString();
120 }
121 }