繁体   English   中英

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

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

我是 Eigen 的新手,我正在尝试在 inputMatrix 的第 2 列和第 3 列使用 atan2() function。
atan2 function 带有红色下划线,告诉我“class Eigen::Matrix has no member "atan2"”,如果我尝试,我会收到不同的错误:atan2(Z)
-或者-

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

同样,作为 Eigen 的新手,我的理解是我需要在矩阵上使用 .array 来执行操作,但我觉得我在下面这样做了。 请告诉我我做错了什么。

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;
}

只是为了澄清 tan 有两个不同的三角函数。

  • atan2()计算所有四个象限。

  • atan()计算一个和四个象限。

现在, eigen只支持atan() 它计算反正切。

这就是为什么您收到错误"class Eigen::Matrix has no member "atan2""的原因。

但是,使用头文件#include <cmath>#include <valarray>您可以使用 function atan2() valarray还包括atan2()

例如使用头文件#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