函式模板
<complex>

std::polar

template<class T> complex<T> polar (const T& rho, const T& theta = 0);
從極座標分量構造複數
返回一個複數物件(以笛卡爾座標格式),該複數由其極座標分量 rhotheta 定義,其中 rho 是幅值(模),theta 是相位角。返回值中的值與以下情況相同:

1
2
real = rho * cos(theta);
imag = rho * sin(theta);

引數

rho
複數的幅值(模)。
theta
複數的相位角(角度分量)。
Tcomplex 型別的分量型別(即其值型別)。

返回值

rhotheta 形成的極座標格式對應的複數笛卡爾座標等價物。

示例

1
2
3
4
5
6
7
8
9
10
11
12
// polar example
#include <iostream>     // std::cout
#include <complex>      // std::complex, std::polar

int main ()
{
  std::cout << "The complex whose magnitude is " << 2.0;
  std::cout << " and phase angle is " << 0.5;
  std::cout << " is " << std::polar (2.0, 0.5) << '\n';

  return 0;
}

輸出

The complex whose magnitude is 2 and phase angle is 0.5 is (1.75517,0.958851)


另見