diff --git a/blocks/math.js b/blocks/math.js
index 9f95654af..18f664368 100644
--- a/blocks/math.js
+++ b/blocks/math.js
@@ -372,6 +372,29 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
"colour": "%{BKY_MATH_HUE}",
"tooltip": "%{BKY_MATH_RANDOM_FLOAT_TOOLTIP}",
"helpUrl": "%{BKY_MATH_RANDOM_FLOAT_HELPURL}"
+ },
+
+ // Block for calculating atan2 of [X] and [Y].
+ {
+ "type": "math_atan2",
+ "message0": "%{BKY_MATH_ATAN2_TITLE}",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "X",
+ "check": "Number"
+ },
+ {
+ "type": "input_value",
+ "name": "Y",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "output": "Number",
+ "colour": "%{BKY_MATH_HUE}",
+ "tooltip": "%{BKY_MATH_ATAN2_TOOLTIP}",
+ "helpUrl": "%{BKY_MATH_ATAN2_HELPURL}"
}
]); // END JSON EXTRACT (Do not delete this comment.)
diff --git a/demos/code/index.html b/demos/code/index.html
index 3210db5e0..e591c6a54 100644
--- a/demos/code/index.html
+++ b/demos/code/index.html
@@ -200,6 +200,18 @@
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+
diff --git a/demos/graph/index.html b/demos/graph/index.html
index dd5401e29..ec6ba5e36 100644
--- a/demos/graph/index.html
+++ b/demos/graph/index.html
@@ -145,6 +145,18 @@
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+
diff --git a/demos/rtl/index.html b/demos/rtl/index.html
index 917d6f906..240cf8d20 100644
--- a/demos/rtl/index.html
+++ b/demos/rtl/index.html
@@ -117,6 +117,7 @@
+
diff --git a/demos/toolbox/index.html b/demos/toolbox/index.html
index 311460e0a..77ee1d58f 100644
--- a/demos/toolbox/index.html
+++ b/demos/toolbox/index.html
@@ -114,6 +114,7 @@
+
diff --git a/generators/dart/math.js b/generators/dart/math.js
index 32660b5f1..1dea19147 100644
--- a/generators/dart/math.js
+++ b/generators/dart/math.js
@@ -485,3 +485,15 @@ Blockly.Dart['math_random_float'] = function(block) {
'import \'dart:math\' as Math;';
return ['new Math.Random().nextDouble()', Blockly.Dart.ORDER_UNARY_POSTFIX];
};
+
+Blockly.Dart['math_atan2'] = function(block) {
+ // Arctangent of point (X, Y) in degrees from -180 to 180.
+ Blockly.Dart.definitions_['import_dart_math'] =
+ 'import \'dart:math\' as Math;';
+ var argument0 = Blockly.Dart.valueToCode(block, 'X',
+ Blockly.Dart.ORDER_NONE) || '0';
+ var argument1 = Blockly.Dart.valueToCode(block, 'Y',
+ Blockly.Dart.ORDER_NONE) || '0';
+ return ['Math.atan2(' + argument1 + ', ' + argument0 + ') / Math.pi * 180',
+ Blockly.Dart.ORDER_MULTIPLICATIVE];
+};
diff --git a/generators/javascript/math.js b/generators/javascript/math.js
index 191e7af1e..fa7d7714b 100644
--- a/generators/javascript/math.js
+++ b/generators/javascript/math.js
@@ -411,3 +411,13 @@ Blockly.JavaScript['math_random_float'] = function(block) {
// Random fraction between 0 and 1.
return ['Math.random()', Blockly.JavaScript.ORDER_FUNCTION_CALL];
};
+
+Blockly.JavaScript['math_atan2'] = function(block) {
+ // Arctangent of point (X, Y) in degrees from -180 to 180.
+ var argument0 = Blockly.JavaScript.valueToCode(block, 'X',
+ Blockly.JavaScript.ORDER_COMMA) || '0';
+ var argument1 = Blockly.JavaScript.valueToCode(block, 'Y',
+ Blockly.JavaScript.ORDER_COMMA) || '0';
+ return ['Math.atan2(' + argument1 + ', ' + argument0 + ') / Math.PI * 180',
+ Blockly.JavaScript.ORDER_DIVISION];
+};
diff --git a/generators/lua/math.js b/generators/lua/math.js
index eefcee4ae..a105371e5 100644
--- a/generators/lua/math.js
+++ b/generators/lua/math.js
@@ -425,3 +425,13 @@ Blockly.Lua['math_random_float'] = function(block) {
// Random fraction between 0 and 1.
return ['math.random()', Blockly.Lua.ORDER_HIGH];
};
+
+Blockly.Lua['math_atan2'] = function(block) {
+ // Arctangent of point (X, Y) in degrees from -180 to 180.
+ var argument0 = Blockly.Lua.valueToCode(block, 'X',
+ Blockly.Lua.ORDER_NONE) || '0';
+ var argument1 = Blockly.Lua.valueToCode(block, 'Y',
+ Blockly.Lua.ORDER_NONE) || '0';
+ return ['math.deg(math.atan2(' + argument1 + ', ' + argument0 + '))',
+ Blockly.Lua.ORDER_HIGH];
+};
\ No newline at end of file
diff --git a/generators/php/math.js b/generators/php/math.js
index 5100d0f4b..cef909281 100644
--- a/generators/php/math.js
+++ b/generators/php/math.js
@@ -372,3 +372,13 @@ Blockly.PHP['math_random_float'] = function(block) {
// Random fraction between 0 and 1.
return ['(float)rand()/(float)getrandmax()', Blockly.PHP.ORDER_FUNCTION_CALL];
};
+
+Blockly.PHP['math_atan2'] = function(block) {
+ // Arctangent of point (X, Y) in degrees from -180 to 180.
+ var argument0 = Blockly.PHP.valueToCode(block, 'X',
+ Blockly.PHP.ORDER_COMMA) || '0';
+ var argument1 = Blockly.PHP.valueToCode(block, 'Y',
+ Blockly.PHP.ORDER_COMMA) || '0';
+ return ['atan2(' + argument1 + ', ' + argument0 + ') / pi() * 180',
+ Blockly.PHP.ORDER_DIVISION];
+};
\ No newline at end of file
diff --git a/generators/python/math.js b/generators/python/math.js
index f1307d71a..11e8466e2 100644
--- a/generators/python/math.js
+++ b/generators/python/math.js
@@ -386,3 +386,14 @@ Blockly.Python['math_random_float'] = function(block) {
Blockly.Python.definitions_['import_random'] = 'import random';
return ['random.random()', Blockly.Python.ORDER_FUNCTION_CALL];
};
+
+Blockly.Python['math_atan2'] = function(block) {
+ // Arctangent of point (X, Y) in degrees from -180 to 180.
+ Blockly.Python.definitions_['import_math'] = 'import math';
+ var argument0 = Blockly.Python.valueToCode(block, 'X',
+ Blockly.Python.ORDER_NONE) || '0';
+ var argument1 = Blockly.Python.valueToCode(block, 'Y',
+ Blockly.Python.ORDER_NONE) || '0';
+ return ['math.atan2(' + argument1 + ', ' + argument0 + ') / math.pi * 180',
+ Blockly.Python.ORDER_MULTIPLICATIVE];
+};
diff --git a/msg/messages.js b/msg/messages.js
index 15110d0f5..d3fea6ce9 100644
--- a/msg/messages.js
+++ b/msg/messages.js
@@ -557,6 +557,13 @@ Blockly.Msg.MATH_RANDOM_FLOAT_TITLE_RANDOM = 'random fraction';
/// tooltip - Return a random fraction between 0 and 1. The value may be equal to 0 but must be less than 1.
Blockly.Msg.MATH_RANDOM_FLOAT_TOOLTIP = 'Return a random fraction between 0.0 (inclusive) and 1.0 (exclusive).';
+/// {{Optional}} url - Information about how to calculate atan2.
+Blockly.Msg.MATH_ATAN2_HELPURL = 'https://en.wikipedia.org/wiki/Atan2';
+/// block text - The title of the block that calculates atan2 of point (X, Y). For example, if the point is (-1, -1), this returns -135. %1 is a placeholder for the X coordinate, %2 is the placeholder for the Y coordinate.
+Blockly.Msg.MATH_ATAN2_TITLE = 'atan2 of X:%1 Y:%2';
+/// tooltip - Return the arctangent of point (X, Y) in degrees from -180 to 180. For example, if the point is (-1, -1) this returns -135.
+Blockly.Msg.MATH_ATAN2_TOOLTIP = 'Return the arctangent of point (X, Y) in degrees from -180 to 180.';
+
// Text Blocks.
/// {{Optional}} url - Information about how computers represent text (sometimes referred to as ''string''s).
Blockly.Msg.TEXT_TEXT_HELPURL = 'https://en.wikipedia.org/wiki/String_(computer_science)';
diff --git a/tests/generators/index.html b/tests/generators/index.html
index 23289f767..4a73a3bd6 100644
--- a/tests/generators/index.html
+++ b/tests/generators/index.html
@@ -320,6 +320,7 @@ h1 {
+
diff --git a/tests/generators/math.xml b/tests/generators/math.xml
index 9c1f644f8..3988ebd6e 100644
--- a/tests/generators/math.xml
+++ b/tests/generators/math.xml
@@ -36,6 +36,11 @@
+
+
+
+
+
@@ -1881,4 +1886,64 @@
+
+ test atan2
+ Describe this function...
+
+
+
+
+ atan2
+
+
+
+
+
+
+ -5
+
+
+
+
+ 5
+
+
+
+
+
+
+ 135
+
+
+
+
+
+
+ atan2
+
+
+
+
+
+
+ 0
+
+
+
+
+ -12
+
+
+
+
+
+
+ -90
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/multi_playground.html b/tests/multi_playground.html
index afbcbf8cf..8177a87db 100644
--- a/tests/multi_playground.html
+++ b/tests/multi_playground.html
@@ -289,6 +289,18 @@ h1 {
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+
diff --git a/tests/playground.html b/tests/playground.html
index 39b4283a5..20a216c73 100644
--- a/tests/playground.html
+++ b/tests/playground.html
@@ -519,6 +519,18 @@ h1 {
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+
@@ -848,6 +860,18 @@ h1 {
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+
diff --git a/tests/workspace_svg/index.html b/tests/workspace_svg/index.html
index 53006a634..a4c7aebd3 100644
--- a/tests/workspace_svg/index.html
+++ b/tests/workspace_svg/index.html
@@ -202,6 +202,18 @@ h1 {
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+