简体   繁体   中英

Getting an error while using the atan2() function on two Eigen matrices

I am new to Eigen, and am trying to use the atan2() function on the 2nd and 3rd columns of the inputMatrix.
The atan2 function is underlined red, telling me "class Eigen::Matrix has no member "atan2"", I receive a different error if I try: atan2(Z)
-or-

atan2(A.array(), B.array()) 

Again, being new to Eigen, my understanding is that I need to use.array on the matrix to perform operations but I feel like I did that below. Please tell me what I am doing wrong.

Eigen::MatrixXd sampleFunction(Eigen::MatrixXd inputMatrix)
{
    Eigen::MatrixXd Z, A, B, V;

    A = inputMatrix.col(1);
    B = inputMatrix.col(2);

    Z = (A.array(), B.array());
    V = Z.atan2();

    return V;
}

Just to clarify there are two different trigonometric functions for tan.

  • The atan2() calculates all four of the quadrants.

  • The atan() only calculates one and four quadrants.

Now, eigen only supports atan() . Which computes the arc tangent.

That is why you are getting the error "class Eigen::Matrix has no member "atan2"" .

However, using the headerfile #include <cmath> or #include <valarray> you can use the function atan2() . valarray also includes atan2() .

For example using the headerfile #include <valarray>

#include <iostream> 
#include <valarray>



int main()
{

    double y[] = { 2.0, 1.6, -3.8, 2.3 };
    double x[] = { 3.0, -2.4, 2.0, -1.8 };


    std::valarray<double> ycoords(y, 4);
    std::valarray<double> xcoords(x, 4);

    //Results go to valarray
    std::valarray<double> res = atan2(ycoords, xcoords);

    // print results of atan2() function 
    std::cout << "results:";
    for (size_t i = 0; i < res.size(); ++i)
        std::cout << ' ' << res[i];
    std::cout << ' ';

    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM