MCPcopy Create free account
hub / github.com/ANYbotics/grid_map / firstOrderDerivativeAt

Function firstOrderDerivativeAt

grid_map_core/src/CubicInterpolation.cpp:346–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346double firstOrderDerivativeAt(const Matrix &layerData, const Index &index, Dim2D dim,
347 double resolution)
348{
349 const int numCol = layerData.cols();
350 const int numRow = layerData.rows();
351
352 double left, right;
353 switch (dim) {
354 case Dim2D::X: {
355 left = layerData(bindIndexToRange(index.x() + 1, numRow), index.y());
356 right = layerData(bindIndexToRange(index.x() - 1, numRow), index.y());
357 break;
358 }
359 case Dim2D::Y: {
360 left = layerData(index.x(), bindIndexToRange(index.y() + 1, numCol));
361 right = layerData(index.x(), bindIndexToRange(index.y() - 1, numCol));
362 break;
363 }
364 default: {
365 throw std::runtime_error("Unknown derivative direction");
366 }
367 }
368
369 const double perturbation = resolution;
370 // central difference approximation
371 // we need to multiply with resolution since we are
372 // operating in scaled coordinates
373 return (right - left) / (2.0 * perturbation) * resolution;
374}
375
376double mixedSecondOrderDerivativeAt(const Matrix &layerData, const Index &index, double resolution)
377{

Callers 1

getFirstOrderDerivativesFunction · 0.85

Calls 1

bindIndexToRangeFunction · 0.85

Tested by

no test coverage detected