MathArctan2

正接が指定された2つの数値の商である角度(ラジアン単位)を返します。

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;
//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数                                              |
//+------------------------------------------------------------------+
void OnStart()
 {
  vector delta=vector::Full(10,10);
  delta[0]=0;
//--- deltaステップで-1〜2 piの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=0; i<10; i++)
    {
    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", 0, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT);
  ExtGraph.CurveAdd(x_array, y_array, ColorToARGB(colour), CURVE_LINES);
  ExtGraph.IndentUp(30);
  ExtGraph.CurvePlotAll();
  string text1="Press ESC to delete the graph and stop the script, or";
  string text2="Press PgDn to create a screen, delete the graph and stop the script";
  ExtGraph.TextAdd(54, 9, text1, ColorToARGB(clrBlack));
  ExtGraph.TextAdd(54,21, text2, ColorToARGB(clrBlack));
  ExtGraph.Update();
 }
//+------------------------------------------------------------------+
//| スクリーンショットを撮り、画像をファイルに保存する                                |
//+------------------------------------------------------------------+
bool MakeAndSaveScreenshot(const string file_name)
 {
  string file_names[];
  ResetLastError();
  int selected=FileSelectDialog("Save Picture", NULL, "All files (*.*)|*.*", FSD_WRITE_FILE, file_names, file_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(0, file_names[0], GRAPH_WIDTH, GRAPH_HEIGHT);
  ChartSetInteger(0,CHART_SHOW,true);
  return(res);
 }

 

結果:

MathArctan2_Screenshot

参照

実数型(double、float)統計科学的チャートクライアント端末プロパティ