Registered Member
|
Does Eigen have support for calculating atan/atan2 on an Eigen Array? I can't seem to find any mention of it in the documentation.
Basically I have two arrays:
If Eigen doesn't currently have support for this, how would I go about extending the Eigen's Array base class to implement this functionality (I presume I could use std::atan/std::atan2 to perform the calculations)? |
Registered Member
|
This bugtracker seems relevant: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=80
The attached patch (from a month ago) implements atan. You could try applying it to the version you have, or filter out the relevant code, or wait for it to be in a release version. |
Registered Member
|
It is relevant for atan, but I require atan2 support (See: http://stackoverflow.com/questions/283406/what-is-the-difference-between-atan-and-atan2-in-c) |
Registered Member
|
In fairness you asked for either one.
To emulate atan2, you could divide one by the other first, although you'd still need to figure out the quadrants somehow (if you need that). Your best option might be to loop through and do it manually, but I'm quite new to eigen myself so I'll leave assertions like that to the experts. Alternatively you could use complex numbers, since atan2 effectively gives the argument of a complex number. But again I don't think support for that is built-in so you'd still be looping through each element. |
Moderator
|
You can probably use binaryExpr and ptr_fun, something like: A.binaryExpr(B, std::ptr_fun(atan2))
|
Registered Member
|
Hi,
i know, this post is a little bit older... but the function A.binaryExpr(B, std::ptr_fun(atan2)) doesn't work for me... i get the following error:
I am using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 Can someone help me in this dark hour? O_O Thx BL |
Moderator
|
this is because there are multiple overloads of std::atan2, so either pass the C version, or make your own, or use a lambda:
|
Registered Member
|
Yeah, it works! Thank you very much,
greetings from Austria! Buzzzz |
Registered Member
|
Out of curiosity, what is blocking Eigen from providing direct support to atan2 instead of having the users rely on the binaryExpr?
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]