boost::geometry::intersection
От: _sv_  
Дата: 10.01.20 23:41
Оценка:
Добрвый вечер всем.

Получаю неожиданный результат у boost::geometry::intersection
Серый и голубой — исходные полигоны. Красные точки — исходные вершины ломанной, вдоль которой построен полигон.
Результат intersection с моей точки зрения должен идти вдоль голубых линий.
Однако все "липнет" к существующим вершинам. Новые не добавляются.
Картинка и код — ниже.




#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>

using namespace boost::geometry::model;
using namespace boost::multiprecision;

typedef polygon<d2::point_xy<double> > my_polygon_t;
typedef std::vector<my_polygon_t>      my_polygons_t;

int main () {

    my_polygon_t in1, in2;

    boost::geometry::read_wkt (
        "POLYGON((3600.000000000000000 16320.000000000000000,   3839.000000000000000 16320.000000000000000,"
        "3839.000000000000000 16639.000000000000000,   3600.000000000000000 16639.000000000000000 ))", in1);

    boost::geometry::read_wkt (
        "POLYGON(("
        "4406.149999999999636  15806.600000000000364,  4409.229999999999563  15821.899999999999636,  4419.989999999999782  15853.500000000000000,  4436.909999999999854  15880.200000000000728,"
        "4444.079999999999927  15900.200000000000728,  4447.670000000000073  15925.299999999999272,  4445.109999999999673  15939.399999999999636,  4433.829999999999927  15962.899999999999636,"
        "4404.609999999999673  16012.700000000000728,  4393.340000000000146  16020.600000000000364,  4344.899999999999636  16045.500000000000000,  4306.710000000000036  16057.799999999999272,"
        "4272.619999999999891  16072.399999999999636,  4260.060000000000400  16085.899999999999636,  4250.829999999999927  16100.500000000000000,  4230.590000000000146  16195.899999999999636,"
        "4204.189999999999600  16340.799999999999272,  4179.579999999999927  16365.799999999999272,  4160.100000000000364  16381.500000000000000,  4131.909999999999854  16398.700000000000728,"
        "4095.519999999999982  16425.299999999999272,  3849.469999999999800  16495.500000000000000,  3821.789999999999964  16500.099999999998545,  3787.440000000000055  16506.299999999999272,"
        "3775.650000000000091  16513.500000000000000,  3685.949999999999818  16645.200000000000728,  3672.110000000000127  16652.900000000001455,  3577.789999999999964  16810.900000000001455,"
        "3526.530000000000200  16882.599999999998545,  3526.019999999999982  16888.000000000000000,  3618.030000000000200  16932.200000000000728,  3799.750000000000000  16833.900000000001455,"
        "3920.210000000000036  16785.500000000000000,  3999.150000000000091  16778.500000000000000,  4004.530000000000200  16760.799999999999272,  4010.420000000000073  16756.500000000000000,"
        "4014.010000000000218  16758.500000000000000,  4020.159999999999854  16773.400000000001455,  4024.780000000000200  16777.500000000000000,  4041.179999999999836  16780.400000000001455,"
        "4052.199999999999818  16778.799999999999272,  4083.469999999999800  16769.799999999999272,  4148.060000000000400  16748.799999999999272,  4211.880000000000109  16739.400000000001455,"
        "4246.729999999999563  16728.900000000001455,  4348.229999999999563  16667.599999999998545,  4359.760000000000218  16656.000000000000000,  4411.020000000000437  16564.299999999999272,"
        "4426.399999999999636  16553.700000000000728,  4436.140000000000327  16549.599999999998545,  4532.250000000000000  16538.700000000000728,  4650.920000000000073  16515.299999999999272,"
        "5053.050000000000182  16422.200000000000728,  5047.930000000000291  16401.000000000000000,  5034.090000000000146  16402.299999999999272,  5032.800000000000182  16394.900000000001455,"
        "5066.380000000000109  16387.700000000000728,  5075.350000000000364  16418.599999999998545,  5183.770000000000437  16396.400000000001455,  5290.390000000000327  16372.799999999999272,"
        "5319.090000000000146  16357.100000000000364,  5329.340000000000146  16350.899999999999636,  5411.869999999999891  16144.700000000000728,  5444.680000000000291  16052.899999999999636,"
        "5486.710000000000036  15809.200000000000728,  5502.090000000000146  15717.399999999999636,  5485.689999999999600  15712.000000000000000,  5486.199999999999818  15695.799999999999272,"
        "5339.079999999999927  15664.399999999999636,  5327.289999999999964  15679.000000000000000,  5218.369999999999891  15647.399999999999636,  5215.420000000000073  15629.700000000000728,"
        "5158.899999999999636  15616.700000000000728,  5138.529999999999745  15636.600000000000364,  5120.199999999999818  15734.299999999999272,  5117.260000000000218  15750.700000000000728,"
        "5071.510000000000218  15741.000000000000000,  5046.390000000000327  15731.500000000000000,  5029.220000000000255  15728.399999999999636,  5029.220000000000255  15928.799999999999272,"
        "5011.789999999999964  15937.299999999999272,  5011.020000000000437  15766.600000000000364,  5010.510000000000218  15697.700000000000728,  5002.050000000000182  15597.299999999999272,"
        "4998.970000000000255  15583.399999999999636,  4995.130000000000109  15581.399999999999636,  4950.529999999999745  15587.200000000000728,  4906.960000000000036  15607.200000000000728,"
        "4904.399999999999636  15612.899999999999636,  4909.520000000000437  15725.100000000000364,  4835.449999999999818  15729.000000000000000,  4831.100000000000364  15737.700000000000728,"
        "4838.529999999999745  15869.899999999999636,  4848.529999999999745  15972.700000000000728,  4855.960000000000036  16045.700000000000728,  4852.109999999999673  16035.200000000000728,"
        "4833.920000000000073  15848.399999999999636,  4824.949999999999818  15733.799999999999272,  4799.960000000000036  15724.700000000000728,  4749.079999999999927  15683.600000000000364,"
        "4733.189999999999600  15667.500000000000000,  4479.449999999999818  15805.899999999999636,  4416.659999999999854  15796.600000000000364 ))", in2);

    boost::geometry::correct (in1);
    boost::geometry::correct (in2);

    my_polygons_t output;
    boost::geometry::intersection (in1, in2, output);

    for (size_t id = 0; id < output.size (); id++) {
        const my_polygon_t& ref = output[id];
        std::cout << "Intersection: " << boost::geometry::wkt (ref) << "\n";
    }

    return 0;
}
Re: boost::geometry::intersection
От: vng Беларусь https://organicmaps.app/
Дата: 13.01.20 11:20
Оценка: +1
Здравствуйте, _sv_, Вы писали:

__>Добрвый вечер всем.


__>Получаю неожиданный результат у boost::geometry::intersection

__>Серый и голубой — исходные полигоны. Красные точки — исходные вершины ломанной, вдоль которой построен полигон.
__>Результат intersection с моей точки зрения должен идти вдоль голубых линий.
__>Однако все "липнет" к существующим вершинам. Новые не добавляются.
__>Картинка и код — ниже.

Если нужны операции с полигонами, то лучше использовать boost::polygon. Пару лет назад щупал boost::geometry и тоже был удивлен их "округлением" координат.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.