This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Any have a "Eigen Geometry Hello World" program?

Tags: None
(comma "," separated)
chrisalbertson
Registered Member
Posts
3
Karma
0
I have some beginner questions about using Geometry. I've been reading the online docs but the examples generate many errors.

Would anyone have an "Eigen Geometry Hello World" program.

I've been working on a simple demo program to do the following

1) define a vector3f
2) create a rotation and translation transform
3) combine the above two transforms
4) apply the transform to the vector from step #1
5) print the result.

If I can get this to work I'm home free but I've been trying example from the "getting started" guide with no luck. I get many dozens of cascading error messages from examples I carefully cut and pasted into Eclipse. This leads me to wonder of the examples are out of date?

My actually task (robot kinematics) is more complex but if I can get the about to go, I'll work from there.

Thanks.
jitseniesen
Registered Member
Posts
204
Karma
2
Here is a simple program along the lines you suggest which I just tested:
Code: Select all
#include <Eigen/Dense>
#include <iostream>

using namespace Eigen;
using namespace std;

int main()
{
  Vector3d v(1,2,3);  // a vector
  AngleAxisd rot(0.5*M_PI, Vector3d::UnitY()); // rotation of pi/2 radians
  cout << "Applying rotation yields:" << endl << rot * v << endl;
  Translation<double,3> tr(Vector3d::UnitZ()); // translation in z-direction
  cout << "Applying translation yields:" << endl << tr * v << endl;
  Affine3d f = rot * tr; // combine in one transformation
  cout << "Applying both yields:" << endl <<  f * v << endl;
}
Does this work for you? If yes, can you suggest some improvements to our documentation (I do not use the Geometry module myself)? If no, it would probably help if you could give us the error messages you get.
chrisalbertson
Registered Member
Posts
3
Karma
0
EDIT: See text below for explanation. I replace the first three lines of you program with these for linesand all errors go away
Code: Select all
   Vector3d v(1,2,3);  // a vector
   const Vector3d uy(0,1,0);
   AngleAxisd rot(0.5*M_PI, uy); // rotation of pi/2 radians
   cout << "Applying rotation yields:" << endl << rot * v << "\n";


Notice I only have to replace one of the endl and my system needs a hint to see your UnitY was in fact a const.

** end EDIT **

Plowing around in the documentation I found why some of the example don't work, they use version 2 of Eigen. I of course could be see this until I read the part about converting from version 2 to version 3.

You code compiles and produces resuts. Thanks. I've not checked if the results are correct. But I assume so.

One think is that on my platform (Eclipse on Mac OS X) your example compiles clean but the Eclipse editor reports errors. I guess it most use some other method then running gcc to find errors. They are

1) "endl" in improperly overloaded. on the first and third uses but not on the second. You have used endl three times and two have red underlines under them. It is not obvious at all how the second one is different. The easy work around is "\n" in place of endl.

2) "rot" has invalid augments. Eclipse gives my many suggestions but does not see that you have written one of them. The work around for this, I'm sure is dome type case. Eclipse wants a matrix as the second argument after the angle.

But when I click build, or build from the terminal it works fine with no errors My problem before seemed b=to be bad examples in the documentation.

In general if you want documentation suggestion it's use use ONLY full working examples that include the entire d=source code file or at least links to a page with a full file.


Thanks again. I will now see about expanding this a few lines at a time to explore all the functionality I need. It is so much easier when you have something that works to start with. I'm working in robot kinematics, trying to lean how to make a natural looking gait for a legged robot.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
which examples in the documentation does not work anymore? Most of our examples (including most ode snippets) are compiled and run during the doc generation.
chrisalbertson
Registered Member
Posts
3
Karma
0
ggael wrote:which examples in the documentation does not work anymore? Most of our examples (including most ode snippets) are compiled and run during the doc generation.


I could not get "USING_PART_OF_NAMESPACE_EIGEN" to work. also I think maybe it's my build environment this has issues but I find I have to do work arounds like this

Code: Select all
Vector3d foot;
   foot = (Vector3d)(affine * vZero);

Because this
Code: Select all
Vector3d foot;
   foot = affine * vZero;

will not compile. It claims there is no = operator for type ?
Yes type question mark

I also need to do this hack to make the compiler work
Code: Select all
const Vector3d uz(0,0,1);
   AngleAxisd rot(0.5*M_PI, uy);

because this fails,
Code: Select all
AngleAxisd rot(0.5*M_PI, Vector3d::UnitY());

because it can't figure out the type of Vector3d::UnitY()

This is still failing to work but the work around is trivial
cout << "abcd.." << someVector << endl // Compiler claims it can overload the << operator
cout << "abcd.." << someVector << "\n" // this is the work around

I'm finding that if I work at it I can find work arounds. So it was good to have your "Hello World" that I know could be made to work
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
The macro USING_PART_OF_NAMESPACE_EIGEN has been removed from Eigen2 to Eigen3. I cannot find any example that make use of it. Make sure you are not reading the Eigen2 documentation.

All your examples work for me with both gcc and clang and default compiler on macosx so when you say "error" are you referring to compiler errors or error reported by Eclipse's parser? If the later, then report them to the Eclipse team!


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]