GeoMagneticElements.java

  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. import java.io.Serializable;
  19. import java.text.NumberFormat;

  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;

  22. /** Contains the elements to represent a magnetic field at a single point.
  23.  * @author Thomas Neidhart
  24.  */
  25. public class GeoMagneticElements implements Serializable {

  26.     /** Serializable UID. */
  27.     private static final long serialVersionUID = 1881493738280586855L;

  28.     /** The magnetic field vector (East=X, North=Y, Nadir=Z). */
  29.     private Vector3D b;

  30.     /** The magnetic inclination in radians. */
  31.     private double inclination;

  32.     /** The magnetic declination in radians. */
  33.     private double declination;

  34.     /** The magnetic total intensity, in nano Teslas. */
  35.     private double totalIntensity;

  36.     /** The magnetic horizontal intensity, in nano Teslas. */
  37.     private double horizontalIntensity;

  38.     /** Construct a new element with the given field vector. The other elements
  39.      * of the magnetic field are calculated from the field vector.
  40.      * @param b the magnetic field vector
  41.      */
  42.     public GeoMagneticElements(final Vector3D b) {
  43.         this.b = b;

  44.         horizontalIntensity = FastMath.hypot(b.getX(), b.getY());
  45.         totalIntensity = b.getNorm();
  46.         declination = FastMath.atan2(b.getY(), b.getX());
  47.         inclination = FastMath.atan2(b.getZ(), horizontalIntensity);
  48.     }

  49.     /** Returns the magnetic field vector in nTesla.
  50.      * @return the magnetic field vector in nTesla
  51.      */
  52.     public Vector3D getFieldVector() {
  53.         return b;
  54.     }

  55.     /** Returns the inclination of the magnetic field in radians.
  56.      * @return the inclination (dip) in radians
  57.      */
  58.     public double getInclination() {
  59.         return inclination;
  60.     }

  61.     /** Returns the declination of the magnetic field in radians.
  62.      * @return the declination (dec) in radians
  63.      */
  64.     public double getDeclination() {
  65.         return declination;
  66.     }

  67.     /** Returns the total intensity of the magnetic field (= norm of the field vector).
  68.      * @return the total intensity in nTesla
  69.      */
  70.     public double getTotalIntensity() {
  71.         return totalIntensity;
  72.     }

  73.     /** Returns the horizontal intensity of the magnetic field (= norm of the
  74.      * vector in the plane spanned by the x/y components of the field vector).
  75.      * @return the horizontal intensity in nTesla
  76.      */
  77.     public double getHorizontalIntensity() {
  78.         return horizontalIntensity;
  79.     }

  80.     @Override
  81.     public String toString() {
  82.         final NumberFormat f = NumberFormat.getInstance();
  83.         final StringBuilder sb = new StringBuilder();
  84.         sb.append("MagneticField[");
  85.         sb.append("B=");
  86.         sb.append(b.toString(f));
  87.         sb.append(",H=");
  88.         sb.append(f.format(getHorizontalIntensity()));
  89.         sb.append(",F=");
  90.         sb.append(f.format(getTotalIntensity()));
  91.         sb.append(",I=");
  92.         sb.append(f.format(getInclination()));
  93.         sb.append(",D=");
  94.         sb.append(f.format(getDeclination()));
  95.         sb.append("]");
  96.         return sb.toString();
  97.     }
  98. }