I have two vectors like
int main(int argc, char *argv())
{
.........
Vector3f center(0.4,0.1,0.3) ;
Vector3f point(0.1,0.2,0.7);
.......
}
How can I calculate Manhattan distance using eigen library? I am using VS2010.
This isn't hard as long as you know what Manhattan distance is (though I haven't seen the term used for 3D vectors before) - just have a look in the Eigen API doc for the relevant functions, you'll then find that the following works:
Vector3f center(0.4,0.1,0.3) ;
Vector3f point(0.1,0.2,0.7);
Vector3f diff = center - point;
float manh_dist = diff.cwiseAbs().sum();
An alternative is to observe that the Manhattan distance correspond to the L1 norm which can be obtained using the generic lpNorm method with :
manh_dist = (center-point).lpNorm<1>();
See this page for reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With