Returns the angle φ of the Cartesian coordinates (x,y)
ATAN2_YX returns the angle j of the Cartesian coordinates (x,y) within the range of -p to +p.
Input
Cartesian y coordinate
Cartesian x coordinate
Output
Each position P of the two-dimensional coordinates can be defined by Cartesian coordinates P(x,y) or by polar coordinates P(r,j) (r = radius, j = angle).
Define ATAN2_YX as follows:
ATAN2_YX(y,x) |
x |
y |
---|---|---|
x > 0 |
||
x < 0 |
y ³ 0 |
|
y < 0 |
||
x = 0 |
y > 0 |
|
y < 0 |
||
0 |
y = 0 |
Corresponding F instructions: F305_BATAN, F319_ATAN
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
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
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
(* 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 *)