简体   繁体   English

在两个特征矩阵上使用 atan2() function 时出错

[英]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.我是 Eigen 的新手,我正在尝试在 inputMatrix 的第 2 列和第 3 列使用 atan2() function。
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) atan2 function 带有红色下划线,告诉我“class Eigen::Matrix has no member "atan2"”,如果我尝试,我会收到不同的错误: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.同样,作为 Eigen 的新手,我的理解是我需要在矩阵上使用 .array 来执行操作,但我觉得我在下面这样做了。 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.只是为了澄清 tan 有两个不同的三角函数。

  • The atan2() calculates all four of the quadrants. atan2()计算所有四个象限。

  • The atan() only calculates one and four quadrants. atan()计算一个和四个象限。

Now, eigen only supports atan() .现在, eigen只支持atan() Which computes the arc tangent.它计算反正切。

That is why you are getting the error "class Eigen::Matrix has no member "atan2"" .这就是为什么您收到错误"class Eigen::Matrix has no member "atan2""的原因。

However, using the headerfile #include <cmath> or #include <valarray> you can use the function atan2() .但是,使用头文件#include <cmath>#include <valarray>您可以使用 function atan2() valarray also includes atan2() . valarray还包括atan2()

For example using the headerfile #include <valarray>例如使用头文件#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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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