Namespaces
Variants

std:: atan2 (std::valarray)

From cppreference.net
헤더에 정의됨 <valarray>
template < class T >
std:: valarray < T > atan2 ( const std:: valarray < T > & y, const std:: valarray < T > & x ) ;
(1)
template < class T >

std:: valarray < T > atan2 ( const std:: valarray < T > & y,

const typename std:: valarray < T > :: value_type & vx ) ;
(2)
template < class T >

std:: valarray < T > atan2 ( const typename std:: valarray < T > :: value_type & vy,

const std:: valarray < T > & x ) ;
(3)

인수의 부호를 사용하여 사분면을 올바르게 결정하는 방식으로 y / x 의 아크탄젠트를 계산합니다.

1) y x 의 각 대응 값 쌍에 대한 아크탄젠트를 계산합니다.

x. size ( ) ! = y. size ( ) 인 경우 동작은 정의되지 않습니다.

2) vx 와 숫자 배열 y 의 각 값에 대한 아크탄젠트를 계산합니다.
3) 숫자 배열 x 의 각 값과 vy 의 아크탄젠트를 계산합니다.

목차

매개변수

x, y - 역탄젠트를 계산할 숫자 배열
vy, vx - 역탄젠트를 계산할 값

반환값

역탄젠트 계산 결과를 포함하는 숫자 배열.

참고 사항

비한정 함수 ( atan2 )가 계산 수행에 사용됩니다. 해당 함수를 사용할 수 없는 경우, std:: atan2 인수 종속 lookup 에 의해 사용됩니다.

이 함수는 반환 타입이 std::valarray 와 다르게 구현될 수 있습니다. 이 경우, 대체 타입은 다음과 같은 속성을 가집니다:

예제

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <valarray>
void show(char const* title, const std::valarray<double>& va)
{
    std::cout << title << ' ';
    std::for_each(std::begin(va), std::end(va), [](const double x)
    { 
        std::cout << ' ' << std::right << std::setw(4) << x << "°";
    });
    std::cout << '\n';
}
const double pi = std::acos(-1.0); // C++20: std::numbers::pi
int main()
{
    auto degrees_to_radians = [](double const& x) { return (pi * x / 180); };
    auto radians_to_degrees = [](double const& x) { return (180 * x / pi); };
    const std::valarray<double> degrees{-90, -60, -45, -30, 0, 30, 45, 60, 90};
    const std::valarray<double> radians = degrees.apply(degrees_to_radians);
    const auto sin = std::sin(radians);
    const auto cos = std::cos(radians);
    show("(1)", std::atan2(sin, cos).apply(radians_to_degrees));
    show("(2)", std::atan2(sin/cos, 1.0).apply(radians_to_degrees));
    show("(3)", std::atan2(1.0, cos/sin).apply(radians_to_degrees));
}

출력:

(1)   -90°  -60°  -45°  -30°    0°   30°   45°   60°   90°
(2)   -90°  -60°  -45°  -30°    0°   30°   45°   60°   90°
(3)    90°  120°  135°  150°    0°   30°   45°   60°   90°

결함 보고서

다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 3074 C++98 T 가 스칼라와 valarray 모두에서 추론되어 (2,3) 혼합 타입 호출이 허용되지 않음 valarray 에서만 T 를 추론

참고 항목

valarray의 각 요소에 std::asin 함수를 적용합니다
(함수 템플릿)
valarray의 각 요소에 std::acos 함수를 적용합니다
(함수 템플릿)
valarray의 각 요소에 std::atan 함수를 적용합니다
(함수 템플릿)
(C++11) (C++11)
부호를 사용하여 사분면을 결정하는 아크 탄젠트
(함수)
위상각을 반환합니다
(함수 템플릿)