1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef GEOMAGNETIC_FIELD_H 17 #define GEOMAGNETIC_FIELD_H 18 19 #include <cmath> 20 #include <ctime> 21 #include <cstring> 22 #include <iostream> 23 #include <vector> 24 25 #include <stdint.h> 26 #include <stdio.h> 27 #include <time.h> 28 29 class GeomagneticField { 30 public: 31 GeomagneticField(float latitude, float longitude, float altitude, int64_t timeMillis); 32 ~GeomagneticField() = default; 33 float ObtainX(); 34 float ObtainY(); 35 float ObtainZ(); 36 float ObtainGeomagneticDip(); 37 float ObtainDeflectionAngle(); 38 float ObtainLevelIntensity(); 39 float ObtainTotalIntensity(); 40 41 private: 42 std::vector<std::vector<float>> GetSchmidtQuasiNormalFactors(int32_t expansionDegree); 43 void CalculateGeomagneticComponent(double latDiffRad, int64_t timeMillis); 44 void GetLongitudeTrigonometric(); 45 void GetRelativeRadiusPower(); 46 void CalibrateGeocentricCoordinates(float latitude, float longitude, float altitude); 47 void InitLegendreTable(int32_t expansionDegree, float thetaRad); 48 double ToDegrees(double angrad); 49 double ToRadians(double angdeg); 50 }; 51 #endif // GEOMAGNETIC_FIELD_H