• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    cos 세타 구하기
    Last Modify : 10 December, 2010(12:24)
    #include <iostream>
    #include <math.h>
    using namespace std;
    
    #define PI			3.141592654f
    #define RADIANPI	(180/PI)
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	double a = 4.0, b = 5.0, c = 3.0;
    
    	double x = (pow(a, 2) + pow(b, 2) - pow(c, 2)) / (2 * a * b);
    	x = cos(x);
    	wcout << L"result : " << x << endl;
    
    	return 0;
    }
    
    double CLocationTrackingParser::GetDistance(CLocationTrackingData* pStart, CLocationTrackingData* pEnd)
    {
    	/* 
    	Haversine formula:
    
    	R = earth’s radius (mean radius = 6,371km)
    	Δlat  = lat2 - lat1
    	Δlong = long2 - long1
    	a      = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
    	c      = 2 * atan2(√a, √(1-a))
    	d      = R * c 
    	*/
    
    	// NMEA ddmm.mmmm or dddmm.mmmm
    	// ex> 3734.1111 => dd.dddddd...... 37 + (34.1111 /60) = result => fLat1 or fLat2
    	// 리턴되는 값은 km 단위이므로 m단위를 하려면 1000을 곱해주자.
    	//
    	//
    	// 시작점과 끝점에 거리를 알자.
    	//
    	double a=0.0, c=0.0, d=0.0;
    	double dLat   = 0.0;
    	double dLong  = 0.0;
    	double dLat1  = 0.0;
    	double dLong1 = 0.0;
    	double dLat2  = 0.0;
    
    	dLat1  = pStart->GetLatitude();
    	dLong1 = pStart->GetLongitude();
    	dLat2  = pEnd->GetLatitude();
    	
    	dLat   = dLat1 - pEnd->GetLatitude();
    	dLong  = dLong1 - pEnd->GetLongitude();
    	
    	dLat1  *= GetPiRadian();
    	dLong1 *= GetPiRadian();
    	dLat   *= GetPiRadian();
    	dLong  *= GetPiRadian();
    
    	a = (sin(dLat / 2.0) * sin(dLat / 2.0)) + (cos(dLat1) * cos(dLat2)) * (sin(dLong / 2.0) * sin(dLong / 2.0));
    	c = 2 * atan2(sqrt(a), sqrt(1 - a));
    	d = m_nEarthRadius * c;
    
    	return d;
    }
    
    double CLocationTrackingParser::GetAngle(CLocationTrackingData* a, CLocationTrackingData* b, CLocationTrackingData* c)
    {
    	//
    	// cos 제 2법칙 이용
    	// cos = a^2 + b^2 - c^2 / 2 * a * b
    	//
    	//       C
    	//      /
    	//     /
    	//    /
    	//  A -------------------- B
    	//
    	double nAB = 0.0, nAC = 0.0, nBC = 0.0;
    
    	nAB = GetDistance(a, b);
    	nAC = GetDistance(a, c);
    	nBC = GetDistance(b, c);
    
    	double dAngle = 0.0;
    	dAngle = acos((pow(nAB, 2) + pow(nAC, 2) - pow(nBC, 2)) / (2 * nAB * nAC)) * GetRadianPi();
    	return dAngle;
    }
    

    Comment


    입력하3 1508772266



    Locations of visitors to this page