R
R
Roman Andreevich2018-12-04 11:10:11
JavaScript
Roman Andreevich, 2018-12-04 11:10:11

How to collect an array from the coordinates of the selected area through a given step?

Colleagues, good day to all! My sadness is this, I'm making an interactive map on a leaflet, the map is created all right. On this map, the user can select an area (a rectangle is drawn, it doesn’t really matter what is drawn here), I need to collect an array from the data of this rectangle with the coordinates of points that are inside its boundaries.
Well, or fill its perimeter with new small layers - rectangles, their centers can be easily pulled out from getCenter().
If someone has come across this, I will be glad to advice ..
Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serginhold, 2018-12-04
@serginhold

I need to collect an array from the data of this rectangle with the coordinates of the points that are inside its boundaries

was there no linear algebra at the university in the first year?
a point is in a polygon (your rectangle) if the number of intersections of the ray with the point and all sides of the polygon is odd.
those. you take a point about which you want to know whether it is in the polygon or not. You build a segment, at one end is your point, the other end is a point that is exactly outside the polygon. Then foreach along the segments of the polygon, and you check whether the segments intersect, i.e. segment with your point with each segment of the polygon. If the sum of intersections is odd, then the point is inside the polygon.
I think you can google the formula for the intersection of segments.
ps you can also google leaflet point in polygon , and it will probably give you something ready on github

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question