37

I have been trying to find a method that computes the magnitude of a vector in Eigen and I was not able to. Can somebody provide me with the function name of just if it doesn't exist?

I can create a global method that does the job but I prefer not to.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Alex
  • 373
  • 1
  • 3
  • 4
  • A vector in mathematics is different from a CS vector. Exactly what vector are you talking about. – Martin York Apr 10 '11 at 16:32
  • 1
    Martin, CS vectors don't have magnitudes. – Adam Apr 10 '11 at 16:40
  • @Martin I am using http://eigen.tuxfamily.org/index.php?title=Main_Page and I want to get the magnitude of an Eigen::Vector3f instance I have created. – Alex Apr 10 '11 at 16:46

2 Answers2

50

You want .norm(). Note that there's also .squaredNorm(), .normalized() and .normalize().

Calimo
  • 7,510
  • 4
  • 39
  • 61
timday
  • 24,582
  • 12
  • 83
  • 135
5

The method you're looking for is .norm().

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Benoit Jacob
  • 351
  • 2
  • 3