[英]boost::geometry::model::segment constructor for template point type?
如何將boost :: geometry :: model :: segment與模板標記點類型一起使用?
例如,我可以使用模板點類型來計算EuclideanDistance
或DotProduct
,但是要計算PointSegmentDistance
我需要使用boost::geometry::model::segment
,但是我不知道如何初始化它。
此代碼有效似乎我弄錯了,此代碼也不適用於模板標記點類型。 我們如何在模板標記點類型中使用此代碼?
template <typename TPoint>
double EuclideanDistance(const TPoint &pt1, const TPoint &pt2)
{
double distance= boost::geometry::distance(pt1, pt2);
return distance;
}
template <typename TPoint>
double DotProduct(const TPoint &pt1, const TPoint &pt2)
{
double product= boost::geometry::dot_product(pt1, pt2);
return product;
}
該代碼不起作用
template <typename TPoint>
double PointSegmentDistance(const TPoint &pt1, const TPoint &pt2, const TPoint &pt3)
{
double distance= boost::geometry::distance(boost::geometry::model::segment(pt1, pt2), pt3);
return distance;
}
另一種選擇是將其重寫為:
template <typename TPoint>
double PointSegmentDistance(const TPoint &pt1, const TPoint &pt2, const TPoint &pt3)
{
boost::geometry::model::segment<TPoint> segment(pt1,pt2);
double distance= boost::geometry::distance(segment, pt3);
return distance;
}
template <typename TPoint>
bool SegmentSegmentIntersection(const TPoint &pt1, const TPoint &pt2, const TPoint &pt3, const TPoint &pt4)
{
boost::geometry::model::segment<TPoint> segment1(pt1,pt2);
boost::geometry::model::segment<TPoint> segment2(pt3,pt4);
bool result= boost::geometry::intersects(segment1, segment2);
return result;
}
您忘記了模板參數:
template <typename TPoint>
double PointSegmentDistance(const TPoint &pt1, const TPoint &pt2, const TPoint &pt3)
{
double distance= boost::geometry::distance(boost::geometry::model::segment<TPoint>(pt1,pt2), pt3);
// ^ template parameter
return distance;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.