2013-05-09 1 views
4

을 boost_1_48_0 라디안이 다시 돌아옵니다.사용 부스트 내가 일을이 코드를 가지고

나는 부스트 시스템이 어떻게 작동하는지 이해하려고 하루를 보냈다. 예가 약간 얇아서 누군가가 빠른 예를 보여줄 수 있는지 궁금해하고 있었다. 사전에

감사 8+)는

편집

//quantity<degree_base_unit> FlindersSDeg2.value(-37.0); 
//quantity< angle::arcminute_base_unit> FlindersSMin = 57.0; 
//quantity< angle::arcsecond_base_unit> FlindersSSec = 3.72030; 

나는 선언이 어떻게 작동하는지에 대한 이해가 필요합니다 같아요. :)

Edit2가이 :

덕분에 매우 - 어쩌면 내가 시설이 없었다 부스트 &와 함께 할 수있는 방법을 찾고 전체를 보냈다!

double ToDegrees(const Angle & angle) 
{ 
    return static_cast<boost::units::quantity<boost::units::degree::plane_angle>>(angle).value(); 
} 

double ToRadians(const Angle & angle) 
{ 
    return static_cast<boost::units::quantity<boost::units::si::plane_angle>>(angle).value(); 
} 

이는 형태 보증 공장에 의해 보완된다 : 나는 여기 http://www.boost.org/doc/libs/1_47_0/libs/geometry/doc/doxy/doxygen_input/sourcecode/doxygen_1.cpp

void example_dms() 
{ 
/* 
Extension, other coordinate system: 
// Construction with degree/minute/seconds 
boost::geometry::dms<boost::geometry::east> d1(4, 53, 32.5); 

// Explicit conversion to double. 
std::cout << d1.as_value() << std::endl; 

// Conversion to string, with optional strings 
std::cout << d1.get_dms(" deg ", " min ", " sec") << std::endl; 

// Combination with latitude/longitude and cardinal directions 
{ 
    using namespace boost::geometry; 
    point_ll<double, boost::geometry::cs::geographic<boost::geometry::degree> >  canberra(
     latitude<>(dms<south>(35, 18, 27)), 
     longitude<>(dms<east>(149, 7, 27.9))); 
    std::cout << canberra << std::endl; 
} 
*/ 
} 

답변

3

내가 부스트 단위와 각도로 사용하는 일부 변환 방법 여기에이 사용되지 않는 코드를 찾을 수 있기 때문에되었을 수 있습니다 생각 : 도, 분, 초, 학위를 대체 캡처하려면

Angle Degrees(double angleInDegrees) 
{ 
    return angleInDegrees * boost::units::degree::degrees; 
} 

Angle Radians(double angleInRadians) 
{ 
    return Angle(angleInRadians * boost::units::si::radians); 
} 

이 같은 변환 구조체와 위의 두 배로 :

struct DMS 
{ 
    DMS(double value) 
    { 
     degrees = std::floor(value); 
     double rem = (value-degrees) * 60; 
     minutes = std::floor(rem); 
     seconds = (rem-minutes) * 60; 
    } 

    operator double() const 
    { 
     return degrees + minutes/60 + seconds/3600; 
    } 

    double degrees; 
    double minutes; 
    double seconds; 
}; 
+0

안녕하세요 Scott, 빠른 답장을 보내 주셔서 감사합니다. 분과 초를하는 방법에 대한 아이디어? 내가 성공하지 않고 시도한 것을 보여주기 위해 내 게시물을 편집 할 것입니다. – TheIdeasMan

+0

나는 ToDegrees와 double angleInDegrees에서 double return을 3-double, 즉 D, M, S를 포착하기위한 간단한 구조체로 바꾸는 것이 좋습니다. –

+0

좋습니다. 부스트 변수를 초기화하는 방법이 있습니까? 나는 잠깐 C++을 사용 해왔다.하지만 아주 새롭기 때문에 새롭게 등장했다. :) – TheIdeasMan

0

첫 번째 유형의 안전한 공장에서 각도를 반환하지 않습니다.

return Angle(angleInDegrees * boost::units::degree::degrees); 
+0

올바른 유형 변환 (예 : PI/180)이 가능하도록 유형이 올바른지 확인하십시오. 시험이 기능을 사용 : /// 세타는 라디안 단위 (SI) 템플릿 부울 isRad (CONST 부스트 : : 단위 : 수량 <시 :: plane_angle, Y> & 세타)가 true { \t 수익입니다 } /// 다른 각도 단위의 theta 템플릿 부울 isRad (const boost :: units :: quantity , Y> & θ) { \t return false; } – dan

0

을하고 적절한 수치 변환 (즉 PI/180)도 수행 우측 있도록 유형이 있는지 확인하십시오

은 아마 당신은 시도 할 수 있습니다. 이 기능을 사용하여 테스트 해보십시오.

/// theta is radian units (si) 
template<class Y> 
bool isRad(const boost::units::quantity<si::plane_angle, Y>& theta) 
{ 
    return true; 
} 
/// theta in other angular units 
template<class System, class Y> 
bool isRad(const boost::units::quantity<boost::units::unit<boost::units::plane_angle_dimension, 
System>, Y>& theta) 
{ 
    return false; 
} 
관련 문제