题中给的信息不足,因为偏移除了距离要素,还需要角度,这才能确定最终偏移后的数据。有了角度后,可以用三角函数推,很简单,初中的知识function offsetLine(line, d, angle){ //let line = [[1, 1], [4, 2], [5, 5], [7, 6]] //let d = 1 //let angle = 30 //斜边长度d已知,角度angle已知 //对边长度就是y的偏移量 就是 d * sin(angle) ==> d * Math.sin(angle * Math.PI / 180) //邻边长度就是x的偏移量 就是 d * cos(angle) ==> d * Math.cos(angle * Math.PI / 180) let ox = d * Math.cos(angle * Math.PI / 180) let oy = d * Math.sin(angle * Math.PI / 180) return line.map(coords => [coords[0] + ox, coords[1] + oy]) }
题中给的信息不足,因为偏移除了距离要素,还需要角度,这才能确定最终偏移后的数据。有了角度后,可以用三角函数推,很简单,初中的知识