< >
Home » Farmbot开发入门教程 » farmbot开发入门教程-插值

farmbot开发入门教程-插值

说明:

  • 测量值之间的插值如何进行。

设置

// Example data
// (most recent soil height measurement for each 10mm-rounded location where data exists)
var points = [
  { uuid: "A", body: { x: 0, y: 0, z: 0 } },
  { uuid: "B", body: { x: 10, y: 10, z: 10 } },
];

// Example position
var position = { x: 4, y: 4 };

// Library
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.jsdelivr.net/npm/lodash@4/lodash.min.js';
document.head.appendChild(script);

最近的邻居

var distance = (from, to) =>
  Math.pow(Math.pow(to.x - from.x, 2) + Math.pow(to.y - from.y, 2), 0.5);
var nearest = _.sortBy(points.map(p =>
 ({ point: p, distance: distance(position, p.body) })), "distance")[0];
var z = nearest.point.body.z;

// expected z using example data: 0

反距离加权

var distance = (from, to) =>
  Math.pow(Math.pow(to.x - from.x, 2) + Math.pow(to.y - from.y, 2), 0.5);
var nearest = _.sortBy(points.map(p =>
 ({ point: p, distance: distance(position, p.body) })), "distance")[0];
var z = nearest.distance == 0
  ? nearest.point.body.z
  : _.sum(points.map(p => (1 / distance(position, p.body) ** 4) * p.body.z))
  / _.sum(points.map(p => (1 / distance(position, p.body) ** 4)));

// expected z using example data: 1.65

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none