ATAN2_YX

返回笛卡尔坐标(x,y)的角度φ

ATAN2_YX在-p到+p的范围内返回笛卡尔坐标 (xy) 的角度j

参数

输入

y (REAL)

笛卡尔y坐标

x (REAL)

笛卡尔x坐标

输出

VAR_OUT (REAL)
以弧度表示的结果

标注

二维坐标的各个位置P可以由笛卡尔坐标P(x,y)或极坐标P(r,j)(r =半径,j =角度)定义。

如下定义ATAN2_YX

ATAN2_YX(y,x)

x

y

x > 0

x < 0

y ³ 0

y < 0

x = 0

y > 0

y < 0

0

y = 0

示例

POU头

所有用于编程此函数的输入和输出变量已在POU头中声明。 所有编程语言使用相同的POU头。

	VAR
		rPhi1Rad: REAL:=0.0;
		rPhi2Rad: REAL:=0.0;
		rPhi1Degree: REAL:=0.0;
		rPhi2Degree: REAL:=0.0;
	END_VAR	VAR CONSTANT 
		DEGR_OF_RAD: REAL:=57.295779513082320876798154814105;
	END_VAR
	VAR 
		bCalculatePhi1: BOOL:=FALSE;
	END_VAR

LD本体

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,ATAN2_YX!,Instance,13,1,20,5,,?Dy?Dx?C);
B(B_VARIN,,10.0,11,2,13,4,);
B(B_VARIN,,-10.0,11,3,13,5,);
B(B_VAROUT,,rPhi1Rad,20,2,22,4,);
B(B_COMMENT,,Angle value of point in quadrant 2:,1,0,18,1,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,@MUL-2!,Instance,13,1,18,4,,?D?D?C);
B(B_VARIN,,rPhi1Rad,11,1,13,3,);
B(B_VARIN,,DEGR_OF_RAD,11,2,13,4,);
B(B_VAROUT,,rPhi1Degree,18,1,20,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,ATAN2_YX!,Instance,13,1,20,5,,?Dy?Dx?C);
B(B_VARIN,,-5.0,11,2,13,4,);
B(B_VARIN,,5.0,11,3,13,5,);
B(B_VAROUT,,rPhi2Rad,20,2,22,4,);
B(B_COMMENT,,Angle value of point in quadrant 4:,1,0,18,1,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,@MUL-2!,Instance,13,1,18,4,,?D?D?C);
B(B_VARIN,,rPhi2Rad,11,1,13,3,);
B(B_VARIN,,DEGR_OF_RAD,11,2,13,4,);
B(B_VAROUT,,rPhi2Degree,18,1,20,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST本体

(* Angle value of point in quadrant 2 *)
rPhi1Rad:=ATAN2_YX(y := 10.0, x := -10.0); (* Result: 2.3561947 *)
rPhi1Degree := rPhi1Rad * DEGR_OF_RAD;     (* Result: 135.00002 *)
(* Angle value of point in quadrant 4 *)
rPhi2Rad:=ATAN2_YX(y := -5.0, x :=   5.0); (* Result: -0.78539819 *)
rPhi2Degree := rPhi2Rad * DEGR_OF_RAD;     (* Result: -45.0 *)

最后更新日期: 此页面上的反馈松下热线