Hello,
i am trying to get one intersection point between line polygon or line line, i tried typedef model::d2::point_xy<double> point; typedef model::ring< point > ring; typedef model::polygon< point > polygon; typedef model::linestring< point > linestring; boost::geometry::read_wkt( "POLYGON((0 0,1 0, 1 1,0 1))", green); linestring ls; boost::geometry::read_wkt("LINESTRING(0.5 -1,0.5 0.5)", ls); std::vector<point> intersections; boost::geometry::intersection(green, blue, intersections); but it is not working. I only want the point which is on the border. Anyone has an idea for that ? thank you for help. I am really new on boost. |
Hi,
On 13-8-2013 9:25, Hunk wrote: > Hello, > > i am trying to get one intersection point between line polygon or line line, > > i tried > > typedef model::d2::point_xy<double> point; > typedef model::ring< point > ring; > typedef model::polygon< point > polygon; > typedef model::linestring< point > linestring; > boost::geometry::read_wkt( > "POLYGON((0 0,1 0, 1 1,0 1))", green); > linestring ls; > boost::geometry::read_wkt("LINESTRING(0.5 -1,0.5 0.5)", ls); > std::vector<point> intersections; > boost::geometry::intersection(green, blue, intersections); > > but it is not working. I only want the point which is on the border. > Anyone has an idea for that ? > > thank you for help. I am really new on boost. It should work. See for example the function void test_point_output() in intersection.cpp in the test-code (libs/geometry/test/algorithms). But your program will never compile. Where is green/blue declared? What aree you doing with ls? What is not working? Not compiling? Regards, Barend _______________________________________________ Geometry mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/geometry |
Hi,
Barend Gehrels wrote: > Hi, > > On 13-8-2013 9:25, Hunk wrote: >> Hello, >> >> i am trying to get one intersection point between line polygon or line >> line, >> >> i tried >> >> typedef model::d2::point_xy<double> point; >> typedef model::ring< point > ring; >> typedef model::polygon< point > polygon; >> typedef model::linestring< point > linestring; >> boost::geometry::read_wkt( >> "POLYGON((0 0,1 0, 1 1,0 1))", green); >> linestring ls; >> boost::geometry::read_wkt("LINESTRING(0.5 -1,0.5 0.5)", ls); >> std::vector<point> intersections; >> boost::geometry::intersection(green, blue, intersections); >> >> but it is not working. I only want the point which is on the border. >> Anyone has an idea for that ? >> >> thank you for help. I am really new on boost. > > It should work. See for example the function void test_point_output() in > intersection.cpp in the test-code (libs/geometry/test/algorithms). But > your program will never compile. Where is green/blue declared? What aree > you doing with ls? > > What is not working? Not compiling? > And if you correct compilation errors this particular example works. But you should have in mind that model::polygon clockwiseness and closure may be defined. Some algorithms may not work if this isn't set correctly, see 2nd and 3rd template parameters described here: http://www.boost.org/doc/libs/1_54_0/libs/geometry/doc/html/geometry/reference/models/model_polygon.html So you should probably change the polygon type: model::polygon<point, false, false> green; // CCW, open boost::geometry::read_wkt("POLYGON((0 0, 1 0, 1 1, 0 1))", green); or data: model::polygon<point> green; // CW, closed boost::geometry::read_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", green); Regards, Adam _______________________________________________ Geometry mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/geometry |
In reply to this post by Barend
hello sorry my example was wront
my code is typedef boost::geometry::model::d2::point_xy<double> point; typedef boost::geometry::model::ring< point > ring; typedef boost::geometry::model::polygon< point> Polygon; typedef boost::geometry::model::linestring< point > linestring; typedef boost::geometry::model::segment< point > segment; Polygon green, blue; segment line_one(boost::geometry::make<point>(-1.0, -1.0), boost::geometry::make<point>(1.0, 1.0)); segment line_two(boost::geometry::make<point>(4.0, 0.0), boost::geometry::make<point>(0.0, 4.0)); linestring one, two; boost::geometry::append(one, boost::geometry::make<point>(0.0, 0.0)); boost::geometry::append(one, boost::geometry::make<point>(4.0, 4.0)); boost::geometry::append(two, boost::geometry::make<point>(4.0, 0.0)); boost::geometry::append(two, boost::geometry::make<point>(0.0, 4.0)); std::vector<point> points, points2, points3; boost::geometry::intersection(line_one, line_two, points); std::cout << "segments: " << std::endl; for (int i = 0; i < points.size(); ++i) { std::cout << "x: " << points[i].get<0>() << std::endl; std::cout << "y: " << points[i].get<1>() << std::endl; } boost::geometry::intersection(one, two, points2); std::cout << "linestring: " << std::endl; for (int i = 0; i < points2.size(); ++i) { std::cout << "x: " << points2[i].get<0>() << std::endl; std::cout << "y: " << points2[i].get<1>() << std::endl; } Polygon polygon; boost::geometry::append(polygon, boost::geometry::make<point>(0, 0)); boost::geometry::append(polygon, boost::geometry::make<point>(4, 0)); boost::geometry::append(polygon, boost::geometry::make<point>(0, 4)); boost::geometry::append(polygon, boost::geometry::make<point>(0, 0)); boost::geometry::intersection(polygon, line_one, points3); std::cout << "Polygon: " << std::endl; for (int i = 0; i < points3.size(); ++i) { std::cout << "x: " << points3[i].get<0>() << std::endl; std::cout << "y: " << points3[i].get<1>() << std::endl; } he cant do the intersection between segment and polygon. It is possible to define lines with and origin point and a direction? not only a segment? And i want the intersection point on the border of the polygon not the segment inside. Thank you for help |
Hi,
On 16-8-2013 11:54, Hunk wrote: > hello sorry my example was wront Indeed wrong ;-) > he cant do the intersection between segment and polygon. That is correct, that combination is not yet possible. Will be done. However, with a linestring with two points you can do exactly this. > > It is possible to define lines with and origin point and a direction? not > only a segment? No unless you make it yourself (you can easily create a function doing that). By default it is not supported. > > And i want the intersection point on the border of the polygon not the > segment inside. Intersection points, if any, should never be inside indeed, always on the border. Attached my version of your program (now complete and compiling and working). Regards, Barend _______________________________________________ Geometry mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/geometry polygon_linestring_intersection_for_hunk.cpp (2K) Download Attachment |
i have a related question. i slightly
modified the code you previously attached, Barend (see
attachment).
- assume we have an intersection point C of a polygon with a segment/linestring. C lies on the segment defined by the pair of points A and B, which are stored in the polygon. is it possible to return A and B, not only C? - is it possible to have a polygon made of segment, something like boost::geometry::model::polygon< segment > ? questions not directly related to the thread's question, but related to the attached code (should i start a new topic?): - i use a custom point class myPoint. how to register the getter and setter template methods (e.g. get<0>)? - can i register std::shared_ptr<myPoint> instead of myPoint? - why is boost::geometry::model::polygon< std::shared_ptr<point> > not working? thanks simon On 08/19/2013 09:13 PM, Barend Gehrels wrote: Hi, _______________________________________________ Geometry mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/geometry polygon_linestring_intersection_modified.cpp (3K) Download Attachment |
i'm very sorry, i just attached a wrong
(outcommented) code, here's the right one.
cheers simon On 08/20/2013 04:30 PM, Tanaka Simon wrote:
_______________________________________________ Geometry mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/geometry polygon_linestring_intersection_modified.cpp (3K) Download Attachment |
In reply to this post by Tanaka Simon
Hi Tanaka,
(the policy of this list is to avoid top-postings) On 20-8-2013 16:30, Tanaka Simon wrote: Yes, internally the get_turns method has a lot more information, a.o. a segment_identifier which indicate exactly the segment on the polygon (so indirectly also A/B). It is a method in namespace detail::, so not documented and it might ever change, but basically it is usable. But intersection does not return this information indeed. No
Specify just get<0> indeed. Works for me (using clang). If this does not work, for some reason or compiler, you can use boost::geometry::traits to register your point-type. You are not using a macro then, writing some more lines code, but you get much more flexibility then. See e.g. example c05_custom_point_pointer_example.cpp where this is done.
That is (basically) not necessary, because all access to points is equivalent between values, references and pointers. However, that is enabled for pointers, but not (yet) for shared points. I did not try it, but probably won't work. We use boost::is_pointer to check if it is a pointer - that returns probably false for shared_ptr (though I'm not sure). It should be possible to enable this for Boost.Geometry too in the future.
Because of the same reason. You can use polygon<point_pointer>, see the same c05 exampe. Regards, Barend _______________________________________________ Geometry mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/geometry |
Free forum by Nabble | Edit this page |