L / L polyline thickness pressure

This is a matter of algorithms, but hopefully someone can help me. I have a line consisting of latitude / longitude points, and I want to create a polygon from it with a certain predetermined thickness. Thus, basically the polygon would have edges that are parallel to the original polyline on both sides. Any thoughts on the best approach to this?

EDIT: My current plan is to iterate over each of the points, find the slope to the next point, then find parallel lines on both sides and make up the sides of the polygons. I just didn't know if there was an easier way to do this.

+3
source share
2 answers

, , . :

var polygon = [
  {x:0, y:0},
  {x:10, y:0},
  {x:10, y:10},
  {x:0, y:10}
];
var outerPolygon = [];
var innerPolygon = [];
for(var i=1; i<polygon.length; i++){
  var ret = newLines(polygon[i-1], polygon[i]);
  outerPolygon.push(ret[0]);
  innerPolygon.push(ret[1]);
}
function newLines(start, stop){
  var dx = start.x - stop.x;
  var dy = start.y - stop.y;
  var d = Math.sqrt(dx*dx + dy*dy);
  dx /= d;
  dy /= d;
  var rNormal = {dx: dy, dy:-dx};
  var lNormal = {dx: -dy, dy:dx};
  return [
    {start:{
      x:start.x+rNormal.dx,
      y:start.y+rNormal.dy},
     stop:{
      x:stop.x+rNormal.dx,
      y:stop.y+rNormal.dy}
    },
    {start:{
      x:start.x+lNormal.dx,
      y:start.y+lNormal.dy},
     stop:{
      x:stop.x+lNormal.dx,
      y:stop.y+lNormal.dy}
    },
  ];
}
+1

, , , .

+1

Source: https://habr.com/ru/post/1718863/


All Articles