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.DecimalFormat;
  20. import java.text.NumberFormat;

  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.utils.units.UnitsConverter;

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

  28.     /** Serializable UID. */
  29.     private static final long serialVersionUID = 1881493738280586855L;

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

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

  34.     /** The magnetic declination in radians. */
  35.     private double declination;

  36.     /** The magnetic total intensity, in Teslas. */
  37.     private double totalIntensity;

  38.     /** The magnetic horizontal intensity, in Teslas. */
  39.     private double horizontalIntensity;

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

  46.         final double intensityNanoTesla = FastMath.hypot(b.getX(), b.getY());
  47.         horizontalIntensity = UnitsConverter.NANO_TESLAS_TO_TESLAS.convert(intensityNanoTesla);
  48.         totalIntensity = UnitsConverter.NANO_TESLAS_TO_TESLAS.convert(b.getNorm());
  49.         declination = FastMath.atan2(b.getY(), b.getX());
  50.         inclination = FastMath.atan2(b.getZ(), intensityNanoTesla);
  51.     }

  52.     /** Returns the magnetic field vector in Tesla.
  53.      * @return the magnetic field vector in Tesla
  54.      */
  55.     public Vector3D getFieldVector() {
  56.         return b;
  57.     }

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

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

  70.     /** Returns the total intensity of the magnetic field (= norm of the field vector).
  71.      * @return the total intensity in Tesla
  72.      */
  73.     public double getTotalIntensity() {
  74.         return totalIntensity;
  75.     }

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

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