gpt4 book ai didi

c++ - 使用 boost 转换度分秒弧度 boost_1_48_0

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:35 26 4
gpt4 key购买 nike

我已经得到了这个代码:

typedef model::point<double, 2, cs::spherical_equatorial<degree> > degree_point;

degree_point FlindersSE(-37.0, 144.0);

还有这个:

quantity<plane_angle> Flinders = 0.375 * radians; //this works 0.375 radians

但我想将度分和秒转换为弧度,然后再返回。

我花了一天时间试图了解 boost 系统的工作原理 - 示例有点少,所以我想知道是否有人可以展示一个简单的示例?

在此先感谢 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;

我想我需要更好地了解声明的工作原理。 :)

编辑2:

非常感谢 - 也许我花了整个时间寻找使用 boost 的方法,但该设施不存在!我想这可能是因为我在这里找到了这个过时的代码 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;
}
*/
}

最佳答案

以下是我对 boost 单位和角度使用的一些转换方法:

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();
}

这些由类型安全工厂补充:

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;
};

关于c++ - 使用 boost 转换度分秒弧度 boost_1_48_0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16465922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com