簡體   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