Calling a specific C++ method from Objective C with no object -
i need calculate moon phase calling method truephase. problem work in objective c , need call method c++ source don't understand much. tell me how call c++ truephase method objective c?
moon.h
#if _msc_ver > 1000 #pragma once #endif #ifndef __aamoonphases_h__ #define __aamoonphases_h__ #ifndef aaplus_ext_class #define aaplus_ext_class #endif class aaplus_ext_class caamoonphases { public: //static methods static double k(double year); static double meanphase(double k); static double truephase(double k); }; #endif //__aamoonphases_h__
moon.cpp (moon.mm)
#include "stdafx.h" #include "aamoonphases.h" #include "aacoordinatetransformation.h" #include <cmath> #include <cassert> using namespace std; double caamoonphases::k(double year) { return 12.3685*(year - 2000); } double caamoonphases::meanphase(double k) { //convert k t double t = k/1236.85; double t2 = t*t; double t3 = t2*t; double t4 = t3*t; return 2451550.09766 + 29.530588861*k + 0.00015437*t2 - 0.000000150*t3 + 0.00000000073*t4; } double caamoonphases::truephase(double k) { //what return value double jd = meanphase(k); //convert k t double t = k/1236.85; double t2 = t*t; double t3 = t2*t; double t4 = t3*t; double e = 1 - 0.002516*t - 0.0000074*t2; double e2 = e*e; double m = caacoordinatetransformation::mapto0to360range(2.5534 + 29.10535670*k - 0.0000014*t2 - 0.00000011*t3); m = caacoordinatetransformation::degreestoradians(m); double mdash = caacoordinatetransformation::mapto0to360range(201.5643 + 385.81693528*k + 0.0107582*t2 + 0.00001238*t3 - 0.000000058*t4); mdash = caacoordinatetransformation::degreestoradians(mdash); double f = caacoordinatetransformation::mapto0to360range(160.7108 + 390.67050284*k - 0.0016118*t2 - 0.00000227*t3 + 0.000000011*t4); f = caacoordinatetransformation::degreestoradians(f); double omega = caacoordinatetransformation::mapto0to360range(124.7746 - 1.56375588*k + 0.0020672*t2 + 0.00000215*t3); omega = caacoordinatetransformation::degreestoradians(omega); double a1 = caacoordinatetransformation::mapto0to360range(299.77 + 0.107408*k - 0.009173*t2); a1 = caacoordinatetransformation::degreestoradians(a1); double a2 = caacoordinatetransformation::mapto0to360range(251.88 + 0.016321*k); a2 = caacoordinatetransformation::degreestoradians(a2); double a3 = caacoordinatetransformation::mapto0to360range(251.83 + 26.651886*k); a3 = caacoordinatetransformation::degreestoradians(a3); double a4 = caacoordinatetransformation::mapto0to360range(349.42 + 36.412478*k); a4 = caacoordinatetransformation::degreestoradians(a4); double a5 = caacoordinatetransformation::mapto0to360range(84.66 + 18.206239*k); a5 = caacoordinatetransformation::degreestoradians(a5); double a6 = caacoordinatetransformation::mapto0to360range(141.74 + 53.303771*k); a6 = caacoordinatetransformation::degreestoradians(a6); double a7 = caacoordinatetransformation::mapto0to360range(207.14 + 2.453732*k); a7 = caacoordinatetransformation::degreestoradians(a7); double a8 = caacoordinatetransformation::mapto0to360range(154.84 + 7.306860*k); a8 = caacoordinatetransformation::degreestoradians(a8); double a9 = caacoordinatetransformation::mapto0to360range(34.52 + 27.261239*k); a9 = caacoordinatetransformation::degreestoradians(a9); double a10 = caacoordinatetransformation::mapto0to360range(207.19 + 0.121824*k); a10 = caacoordinatetransformation::degreestoradians(a10); double a11 = caacoordinatetransformation::mapto0to360range(291.34 + 1.844379*k); a11 = caacoordinatetransformation::degreestoradians(a11); double a12 = caacoordinatetransformation::mapto0to360range(161.72 + 24.198154*k); a12 = caacoordinatetransformation::degreestoradians(a12); double a13 = caacoordinatetransformation::mapto0to360range(239.56 + 25.513099*k); a13 = caacoordinatetransformation::degreestoradians(a13); double a14 = caacoordinatetransformation::mapto0to360range(331.55 + 3.592518*k); a14 = caacoordinatetransformation::degreestoradians(a14); //convert radians double kint = 0; double kfrac = modf(k, &kint); if (kfrac < 0) kfrac = 1 + kfrac; if (kfrac == 0) //new moon { double deltajd = -0.40720*sin(mdash) + 0.17241*e*sin(m) + 0.01608*sin(2*mdash) + 0.01039*sin(2*f) + 0.00739*e*sin(mdash - m) + -0.00514*e*sin(mdash + m) + 0.00208*e2*sin(2*m) + -0.00111*sin(mdash - 2*f) + -0.00057*sin(mdash + 2*f) + 0.00056*e*sin(2*mdash + m) + -0.00042*sin(3*mdash) + 0.00042*e*sin(m + 2*f) + 0.00038*e*sin(m - 2*f) + -0.00024*e*sin(2*mdash - m) + -0.00017*sin(omega) + -0.00007*sin(mdash + 2*m) + 0.00004*sin(2*mdash - 2*f) + 0.00004*sin(3*m) + 0.00003*sin(mdash + m - 2*f) + 0.00003*sin(2*mdash + 2*f) + -0.00003*sin(mdash + m + 2*f) + 0.00003*sin(mdash - m + 2*f) + -0.00002*sin(mdash - m - 2*f) + -0.00002*sin(3*mdash + m) + 0.00002*sin(4*mdash); jd += deltajd; } else if ((kfrac == 0.25) || (kfrac == 0.75)) //first quarter or last quarter { double deltajd = -0.62801*sin(mdash) + 0.17172*e*sin(m) + -0.01183*e*sin(mdash + m) + 0.00862*sin(2*mdash) + 0.00804*sin(2*f) + 0.00454*e*sin(mdash - m) + 0.00204*e2*sin(2*m) + -0.00180*sin(mdash - 2*f) + -0.00070*sin(mdash + 2*f) + -0.00040*sin(3*mdash) + -0.00034*e*sin(2*mdash - m) + 0.00032*e*sin(m + 2*f) + 0.00032*e*sin(m - 2*f) + -0.00028*e2*sin(mdash + 2*m) + 0.00027*e*sin(2*mdash + m) + -0.00017*sin(omega) + -0.00005*sin(mdash - m - 2*f) + 0.00004*sin(2*mdash + 2*f) + -0.00004*sin(mdash + m + 2*f) + 0.00004*sin(mdash - 2*m) + 0.00003*sin(mdash + m - 2*f) + 0.00003*sin(3*m) + 0.00002*sin(2*mdash - 2*f) + 0.00002*sin(mdash - m + 2*f) + -0.00002*sin(3*mdash + m); jd += deltajd; double w = 0.00306 - 0.00038*e*cos(m) + 0.00026*cos(mdash) - 0.00002*cos(mdash - m) + 0.00002*cos(mdash + m) + 0.00002*cos(2*f); if (kfrac == 0.25) //first quarter jd += w; else jd -= w; } else if (kfrac == 0.5) //full moon { double deltajd = -0.40614*sin(mdash) + 0.17302*e*sin(m) + 0.01614*sin(2*mdash) + 0.01043*sin(2*f) + 0.00734*e*sin(mdash - m) + -0.00514*e*sin(mdash + m) + 0.00209*e2*sin(2*m) + -0.00111*sin(mdash - 2*f) + -0.00057*sin(mdash + 2*f) + 0.00056*e*sin(2*mdash + m) + -0.00042*sin(3*mdash) + 0.00042*e*sin(m + 2*f) + 0.00038*e*sin(m - 2*f) + -0.00024*e*sin(2*mdash - m) + -0.00017*sin(omega) + -0.00007*sin(mdash + 2*m) + 0.00004*sin(2*mdash - 2*f) + 0.00004*sin(3*m) + 0.00003*sin(mdash + m - 2*f) + 0.00003*sin(2*mdash + 2*f) + -0.00003*sin(mdash + m + 2*f) + 0.00003*sin(mdash - m + 2*f) + -0.00002*sin(mdash - m - 2*f) + -0.00002*sin(3*mdash + m) + 0.00002*sin(4*mdash); jd += deltajd; } else { assert(false); } //additional corrections phases double deltajd2 = 0.000325*sin(a1) + 0.000165*sin(a2) + 0.000164*sin(a3) + 0.000126*sin(a4) + 0.000110*sin(a5) + 0.000062*sin(a6) + 0.000060*sin(a7) + 0.000056*sin(a8) + 0.000047*sin(a9) + 0.000042*sin(a10) + 0.000040*sin(a11) + 0.000037*sin(a12) + 0.000035*sin(a13) + 0.000023*sin(a14); jd += deltajd2; return jd; }
rename unit file .m
.mm
. mm files compiled objective-c++ compiler. include source file #include "moon.h"
somewhere @ top of unit file. call within viewdidload
method:
- (void)viewdidload { [super viewdidload]; double k = caamoonphases::k(2015); double phase = caamoonphases::truephase(k); nslog(@"k = %f phase = %f", k, phase); }
i didn't work aa+ you'll have figure out how use caamoonphases yourself, suppose implementation right...
Comments
Post a Comment