MathArctan2

탄젠트가 지정된 두 숫자의 몫인 각도(라디안 단위)를 반환

double MathArctan2(
 double y     // 점의 y 좌표
 double x     // 점의 x좌표
  );

매개변수

y

[in]  Y 좌표 값.

x

[in]  X 좌표 값.

값 반환

MathArctan2는 -π 에서 π 라디안까지, MathTan(θ)=y/x 인 각도 θ를 반환

다음을 주의하십시오:

  • 1사분면 내 (x, y)의 경우 0< θ < π/2
  • 2사분면 내 (x, y)의 경우 π/2< θ ≤ π
  • 3사분면 내 (x, y)의 경우 -π < θ < -π/2
  • 4사분면 내 (x, y)의 경우 -π/2 < θ < 0

사분면의 경계에 있는 점의 경우 반환 값은 다음과 같습니다:

  • y가 0이고 x가 음수가 아닌 경우, θ = 0.
  • y가 0이고 x가 음수인 경우, θ = π.
  • y가 양수이고 x가 0인 경우, θ = π/2.
  • y가 음수이고 x가 0인 경우, θ = -π/2.
  • y가 0이고 x도 0인 경우, θ = 0.

주의

MathArctan2() 함수 대신 atan2() 함수를 사용할 수 있습니다.

 

예:

#define GRAPH_WIDTH  750
#define GRAPH_HEIGHT 350
 
#include <Graphics\Graphic.mqh>
 
CGraphic ExtGraph;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   vector delta=vector::Full(10,10);
   delta[0]=0;
//--- 델타 단계를 사용하여 0에서 2pi까지 101개의 값을 얻습니다.
   vector X=delta.CumSum();
//--- X 벡터의 각 값에 대한 아크 탄젠트 값을 계산합니다.
   vector Y=delta.CumSum();
   
   Print("vector delta = \n",delta);
   Print("vector X = \n",X);
   Print("vector Y = \n",Y);
   
//--- 계산된 값을 벡터에서 배열로 전송합니다.
   double x_array[];;
   double y_array[];;
   X.Swap(x_array);
   Y.Swap(y_array);
   
   double array[10];
   for(int i=0i<10i++)
     {
      array[i]=MathArctan2(y_array[i],x_array[i]);
     }
 
//--- 계산된 벡터 값의 그래프를 그립니다.
   CurvePlot(x_array,y_array,clrDodgerBlue);
 
//--- Escape 또는 PgDn 키를 눌러 그래프를 삭제하고(스크린샷 하기) 종료할 때까지 기다립니다.
   while(!IsStopped())
     {
      if(StopKeyPressed())
         break;
      Sleep(16);
     }
 
//--- 모두 삭제
   ExtGraph.Destroy();
  }
//+------------------------------------------------------------------+
//| ESC를 누르면 'true'를 반환합니다                                    |
//| PgDn을 누르면 그래프 스크린샷을 찍고 'true'를 반환합니다               |
//| 그렇지 않으면 'false'를 반환 합니다                                 |
//+------------------------------------------------------------------+
bool StopKeyPressed()
  {
//--- ESC를 누르면 'true'를 반환합니다.
   if(TerminalInfoInteger(TERMINAL_KEYSTATE_ESCAPE)!=0)
      return(true);
//--- PgDn을 누르고 그래프 스크린샷이 성공적으로 촬영되면 'true'를 반환합니다
   if(TerminalInfoInteger(TERMINAL_KEYSTATE_PAGEDOWN)!=0 && MakeAndSaveScreenshot(MQLInfoString(MQL_PROGRAM_NAME)+"_Screenshot"))
      return(true);
//--- 'false'를 반환합니다 
   return(false);
  }
//+------------------------------------------------------------------+
//| 그래프 객체를 만들고 곡선 그리기                                     |
//+------------------------------------------------------------------+
void CurvePlot(double &x_array[], double &y_array[], const color colour)
  {
   ExtGraph.Create(ChartID(), "Graphic"000GRAPH_WIDTHGRAPH_HEIGHT);
   ExtGraph.CurveAdd(x_arrayy_arrayColorToARGB(colour), CURVE_LINES);
   ExtGraph.IndentUp(30);
   ExtGraph.CurvePlotAll();
stringtext1="그래프를 삭제하고 스크립트를 중지하려면 ESC를 누르십시오. 또는";
stringtext2=" 화면을 만들고 그래프를 삭제하고 스크립트를 중지하려면 PgDn을 누르세요";
   ExtGraph.TextAdd(549text1ColorToARGB(clrBlack));
   ExtGraph.TextAdd(54,21text2ColorToARGB(clrBlack));
   ExtGraph.Update();
  }
//+------------------------------------------------------------------+
//| 스크린샷을 찍어 이미지를 파일로 저장                                  |
//+------------------------------------------------------------------+
bool MakeAndSaveScreenshot(const string file_name)
  {
   string file_names[];
   ResetLastError();
   int selected=FileSelectDialog("Save Picture"NULL"All files (*.*)|*.*"FSD_WRITE_FILEfile_namesfile_name+".png");
   if(selected<1)
     {
      if(selected<0)
         PrintFormat("%s: FileSelectDialog() function returned error %d"__FUNCTION__GetLastError());
      return false;
     }
   
   bool res=false;
   if(ChartSetInteger(0,CHART_SHOW,false))
      res=ChartScreenShot(0file_names[0], GRAPH_WIDTHGRAPH_HEIGHT);
   ChartSetInteger(0,CHART_SHOW,true);
   return(res);
  }

 

결과:

MathArctan2_Screenshot