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

Noobie - Can't multiply two vectors together

Tags: None
(comma "," separated)
kloveridge
Registered Member
Posts
5
Karma
0
I am trying to decide if I want to use Eigen or GLM for my engine math library. GLM just dropped in and did what I expected. But Eigen is given me some issues.

I am using Qt as the development platform. Qt already has heartburn with Eigen with its auto completion abilities. Thats a irritation, but I can live with it. But here's a small problem which makes me worry Eigen just might not be a good fit with Qt. I have a small piece of code that does this:

Code: Select all
   Eigen::Vector2f temp( 2.f, 2.f);
   Eigen::Vector2f result;
   result = temp * temp;


When I try to compile this, I get this error:

/Users/karlloveridge/nile/eigen/Eigen/src/Core/GeneralProduct.h:587: error: static_assert failed "INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS"
EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


I worry that using Eigen in Qt is just going to be a uphill battle.

What am I doing wrong here?
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
I don't know Eigen, but the static_assert is pretty clear, no? There's intentionally no overload for * in "v*v", because it's unclear whether you mean the dot product or the coefficient-wise product. Use the appropriate functions to calculate either of them.

Greetings!


I'm working on the KDevelop IDE.
kloveridge
Registered Member
Posts
5
Karma
0
I looked through the documentation somewhat. they do a lot of multiplication of a matrices. From what I gathered, a Vector2 is just a really small, two element matrix. the examples I saw show them multiplying matrices the way my code above does. I couldn't find a straight forward example of multiplying two vectors together. This is fairly common in 3d math.

Can someone show me a example of how this is done with Eigen?.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Did you try v.dot(w)?

You cannot matrix-multiply [1, 2] with [3, 4], I guess that's why it doesn't work.


I'm working on the KDevelop IDE.
kloveridge
Registered Member
Posts
5
Karma
0
"You cannot matrix-multiply a [1, 2] with [3, 4], maybe that's why it doesn't work?"

Hmm. I'm not sure I follow. I thought I was multiplying two vec2's together and simply dumping the result back into the receiver.

I can do this, and it works fine:

result = temp + temp

I get back result(4.0, 4.0).

I'm clearly missing something obvious here. but Qt's auto complete gives virtually no help with this.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Did you try v.dot(w)?

You can only multiply a 2x1 matrix with a 1x2 one, or a 1x2 with a 2x1 one, or take their scalar product, but not multiply a 2x1 matrix with another 2x1 matrix. That's what the error is about, as far as I understand.

Please recognize the difference between Qt and QtCreator, because it's super confusing if people say Qt instead of QtCreator ;)


I'm working on the KDevelop IDE.
kloveridge
Registered Member
Posts
5
Karma
0
You cannot matrix-multiply a [1, 2] with [3, 4], maybe that's why it doesn't work?

hmm. I'm not sure I follow. I just thought I was multiplying two Vec2's together and getting back the result. I guess because I'm having issues in Qt with Eigen, I worried I had some kind of library issue here.

I tried this same operation with two other math libraries and it worked as expected. I guess if this is a incorrect use of the function, I'll accept that.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
There is no such thing as the multiplication of two 1-column matrices, that's just maths. There's the element-wise product, and the scalar product, but neither of them is just the matrix multiplication of the two matrices (which is undefined!). Use v.dot(w) if you want the scalar product (which is what I understand you want). That should be the same as v.transpose() * w.


I'm working on the KDevelop IDE.
kloveridge
Registered Member
Posts
5
Karma
0
I now realize that. I just thought I was throwing a couple of simple test cases at the library and wasn't thinking. It appears the library is working fine. I just was having a senior moment. ;)
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Ok cool, glad it worked ;)


I'm working on the KDevelop IDE.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I've now moved this topic into the Eigen forum.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]