Juliette Pera wrote:Thanks for your answer.
Here's some more information.
I am going through the list of vertices of a segment, stored in a vector of Eigen::Vector2D and then I am computing the distance from a point stored in Eigen::vector2d to a each segment of my polygon.
I calculate the distance using my own function and then I calculate it using boost function distance.
I declare a segment of type boost::geometry::model::segment<double> in which I add my two vertices that make the segment.
You probably mean boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > ?
Then I display the result for each vertices and I get the same result for every segment using boost.
I hope it's more clear now.
If xsegment_t is of type boost::geometry::model::segment and geom::append() is boost::geometry::append() then it doesn't set the endpoints of a segment. It's because a segment is not a container so appending to it doesn't change it. If xsegment_t was e.g. boost::geometry::model::linestring or instead of bg::append() the endpoints of a segment was passed into the constructor it should work.
The behavior of bg::append() is indeed confusing. Anyway, try using the constructor of bg::model::segement instead:
double distance2 = geom::distance(segment, geom::make_point(P,P));
Please let me know if this helps.
A side note. If the overall goal was to calculate the distance from a point to Polygon2D then you could write your own Ring type (a Polygon without holes), e.g. wrap std::vector<Eigen::Vector2d> and adapt your type to Boost.Geometry Ring concept. Or simply register std::vector<Eigen::Vector2d> as a Ring (though then all std::vectors of Eigen::Vector2d points would be treated as Rings). It'd require to adapt Eigen::Vector2d type to Boost.Geometry Point concept and since Eigen::Vector2d provides operator for element access you would be forced to adapt it manually specializing traits. If the goal was to calculate the closest distance to the edge of Polygon2D then instead of adapting std::vector to the Ring concept you could adapt it to the Linestring concept. Then Boost.Geometry could calculate the distance for you.
Here Boost.Geometry point_xy is adapted:
You could copy it and replace:
model::d2::point_xy<CoordinateType, CoordinateSystem> -> Eigen::Vector2d
CoordinateType -> double
CoordinateSystem -> cs::cartesian
return p.template get<Dimension>(); -> return p[Dimension];
p.template set<Dimension>(value); -> p[Dimension] = value;
Here is an example of adapting std::vector to the Ring concept:
So you could register your vector like this:
should return the distance between Polygon and Point.
Boost-users mailing list