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