I just can not think of an algorithm. There is an array of points with the coordinates of the line, for example: [[55.217949,34.309849] [55.218159,34.309731] [55.21862,34.308819] [55.219311,34.309971] [55.219879,34.31097] [55.222752,34.31599] [55.224361,34.31879 ] [55.224541,34.319031] [55.22464,34.319118] [55.224781,34.319172] [55.227039,34.319031] [55.22995,34.318741] [55.231541,34.31712] [55.232071,34.317051] [55.23357,34.31736]]

It is necessary to build a polygon around the line, and if more precisely, then it is necessary to determine the points along which the polygon will be built.

Line in the polygon http://mdv.me/linepolyline.png

Found on the Internet only this: https://stackoverflow.com/questions/5771908/computing-a-polygon-that-surrounds-a-multi-point-line , but the working solution is not there. I wrote this method here, but it "draws" a completely wrong ground - with intersections, some holes, etc.

public function pointsArea($points, $radius) { $count = count($points); $firstCoords = $points[0]; $lastCoords = $points[$count - 1]; $latDiff = 1/(112/$radius); //radius in km $lonDiff = 1/(64/$radius); $polygonPoints = array(); foreach ($points as $n => $point) { if ($n == 0) { $polygonPoints[] = array(($point[0] + $latDiff), $point[1]); $polygonPoints[] = array($point[0], ($point[1] + $lonDiff)); } if (isset($points[$n + 1])) { $next = $polygonPoints[$n + 1]; if ($next[0] - $point[0]) { } } $polygonPoints[] = array(floatval($point[0] + $latDiff), ($point[1] + $lonDiff)); } foreach ($points as $n => $point) { $polygonPoints[] = array(($point[0] - $latDiff), ($point[1] - $lonDiff)); } $polygonPoints[] = $polygonPoints[0]; return $polygonPoints; } 

Tell me, please, the solution of the forgotten geometry. = (

  • And what is the main task? Determination whether any point belongs to this polygon? - andrew68
  • Like that. It is necessary to query the mongo to pull out all the points in the polygon. - Drimean
  • doroga.tv? or a similar project? - andrew68

1 answer 1

If it's not a secret, but what kind of project is it? ))) You can simply do the same with mongo, just a little easier))

Try this:

 rVector: function(pt1, pt2, width, angle) { var dx = pt2.y - pt1.y; var dy = pt2.x - pt1.x; var l = Math.sqrt(Math.pow(dx, 2)) + Math.sqrt(Math.pow(dy, 2)); if (!l) return pt1; var dxn = dx * Math.cos(angle) - dy * Math.sin(angle); var dyn = dx * Math.sin(angle) + dy * Math.cos(angle); var res = {}; res.y = pt1.y + dxn * width / l; res.x = pt1.x + dyn * width / l; return res; } createPolygon: function (pt1, pt2, width1, width2) { var pts = []; pts.push(rVector(pt1, pt2, width1, 1)); pts.push(rVector(pt1, pt2, width1, -1)); pts.push(rVector(pt2, pt1, width2, 1)); pts.push(rVector(pt2, pt1, width2, -1)); return pts; } 

Well and between 2 points of a polyline it is possible to receive a quadrangle

create_polygon (point1, point2, 2000, 2000)

create_polygon (point2, point3, 2000, 2000)

create_polygon (point3, point4, 2000, 2000)

Try it.

PS In order for this to work to create a polyline along a polyline that would be adequate relative to the earth's surface, you need to do a conversion along the required projection. For example, by mercator.

  • Thank! Indeed, from the angle everything falls into place. In mongo, unfortunately, how to do this I could not find, $ near does not know how to work with lines. = (And the project is internal in the company. Display sales points not far from the roads on employee routes. - Drimean