使用boost转换度、分、秒、弧度
Use boost to convert degrees minutes seconds radians boost_1_48_0
我已经得到了这个代码的工作:
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
但我想做度分秒&转换成弧度,然后再返回。
我花了一天的时间试图了解如何提高系统的工作-例子有点薄在地面上,所以我想知道如果有人可以显示一个快速的例子?
Thanks in advance 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:
非常感谢-也许我花了一整个时间寻找用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;
}
*/
}
以下是我对升压单位和角度使用的一些转换方法:
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;
};
你的第一个类型安全工厂没有返回角度。
也许你可以试试:
return Angle( angleInDegrees * boost::units::degree::degrees);
并确保您有正确的类型,以便进行适当的数字转换(例如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;
}
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 使用Boost Interprocess创建托管共享内存需要很长时间
- Boost::posix_time::ptime舍入到给定的分钟数
- 使用boost转换度、分、秒、弧度