Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distance result error #1374

Closed
Jimyzzp opened this issue Feb 12, 2025 · 1 comment
Closed

distance result error #1374

Jimyzzp opened this issue Feb 12, 2025 · 1 comment

Comments

@Jimyzzp
Copy link

Jimyzzp commented Feb 12, 2025

#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/io/svg/write_svg.hpp>

namespace bg = boost::geometry;

typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
typedef bg::model::linestring<point_t> linestring_t;
typedef bg::model::polygon<point_t> polygon_t;

int main(){
	polygon_t pg1;
	bg::append(pg1.outer(), point_t{1545, 4435});
	bg::append(pg1.outer(), point_t{1545, 4540});
	bg::append(pg1.outer(), point_t{1405, 4540});
	bg::append(pg1.outer(), point_t{1405, 4435});
	linestring_t l2{
		point_t{1435, 4725},
		point_t{1450, 4710},
	};
	double d = bg::distance(pg1, l2); // why the result of d is zero?
    return 0;
}
@vissarion
Copy link
Member

The polygon is invalid because it is declared as closed (and it is not) and as clockwise (and it is not).
If you append the first point at the end and you also reverse the order to be clockwise you will get the correct distance which is 170.

Equivalently, you can just define your polygon as not closed and not clockwise
typedef bg::model::polygon<point_t, false, false> polygon_t;

For more details see the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants