Codeblocks - use Math blocks
Use Math blocks to add, subtract, multiply, divide, and round numbers, as well as to find the square root and perform trigonometry functions.
Transcript
00:00
The Math code blocks contain mathematical blocks to perform a variety of operations.
00:09
These include a block to create a Number Constant, a block containing Operations of arithmetic,
00:16
a block containing Square Root, along with other standard common functions,
00:22
a Trigonometry block, a Rounding block, a Remainder Of block
00:29
and a Constrain block to clamp a number to arrange between a minimum and a maximum value.
00:37
When working with mathematical code blocks,
00:41
it's important to understand the relationship between block grouping and the order of operations.
00:47
Here, we might expect the result to be thirty-six, but instead it calculates at forty.
00:54
This is because each block acts as a grouped parenthetical calculation.
00:60
Here, the same blocks are arranged with this grouping in mind to achieve the expected result of thirty-six.
01:10
Once we understand that each block represents a grouping that correlates to the standard mathematical order of operations,
01:17
we can achieve the results we expect.
01:21
Next, we'll take a look at setting up a rule to calculate the area of a wall.
01:26
First, we'll add an Inventor parameter to the model to hold the calculated square footage.
01:32
This will be used in our product definition form to display a read-only value.
01:38
In the Parameters tab of the product definition, we select Area to adopt it into the form.
01:45
This product definition has been set up to display the length and height in form messages as inches.
01:52
The message blocks have been collapsed, but can be expanded to view the contents.
01:58
Likewise, they can be collapsed again as needed.
02:03
Adding a block to make Area Read Only sets the block up for the next step of adding blocks to calculate it.
02:13
To create the calculation, the Area block is added to the canvas.
02:18
Then, the Length block is added, then copied and pasted using CTRL C and CTRL V on the keyboard.
02:26
Changing the block to Height, we're now ready to add the math Operations block and set it to Multiply.
02:33
Adding the Length and Height blocks to the Multiply block creates the Area calculation.
02:39
Using the right click External Inputs option,
02:42
wraps the block to fit in the canvas better.
02:45
And then a click of the form Update button shows the calculated area.
02:51
Next, we'll determine the diagonal measurement of the wall from corner to corner
02:55
by transforming the Pythagorean theorem to solve for length c.
03:01
An existing variable called Diagonal is used, and then the Square Root block is selected and snapped to it.
03:09
Next, the general Operations block is added twice,
03:13
and one instance is left to do addition, while the second is set to raise the value by a power of two.
03:21
Adding the Length Parameter block calculates the square value
03:25
and then the block is copied and the new block is changed to use the Height.
03:31
Both blocks are added to the Addition block to sum the results of both square parameter values.
03:37
A right click and a selection of External Inputs fits the block for easier reading.
03:45
Adding a Print block to pop up the value of Diagonal
03:48
allows the calculated corner to corner result to be displayed when the form is updated.
03:55
Getting the angles of the diagonal corners can be calculated using the Inverse Tangent Trigonometric block.
04:04
Here, we start by duplicating an existing connected block set.
04:09
Adding the Trigonometry math block and setting it to use the atan function
04:14
sets us up to quickly reuse existing code blocks from further up in the canvas.
04:20
Changing the variable from diagonal to one previously created, called angle A, completes this block rule.
04:29
Using Duplicate Connected to copy the entire block allows us to create a rule to solve for the remaining angle with ease and efficiency.
04:40
Updating the form shows us the results.
04:44
In summary, it's important to know that Math blocks evaluate as parenthetical groups
04:52
following standard order of operations.
04:55
There are numerous Math blocks to explore listed in the Math block library,
04:60
combining to allow for a rich set of mathematical calculations.
00:00
The Math code blocks contain mathematical blocks to perform a variety of operations.
00:09
These include a block to create a Number Constant, a block containing Operations of arithmetic,
00:16
a block containing Square Root, along with other standard common functions,
00:22
a Trigonometry block, a Rounding block, a Remainder Of block
00:29
and a Constrain block to clamp a number to arrange between a minimum and a maximum value.
00:37
When working with mathematical code blocks,
00:41
it's important to understand the relationship between block grouping and the order of operations.
00:47
Here, we might expect the result to be thirty-six, but instead it calculates at forty.
00:54
This is because each block acts as a grouped parenthetical calculation.
00:60
Here, the same blocks are arranged with this grouping in mind to achieve the expected result of thirty-six.
01:10
Once we understand that each block represents a grouping that correlates to the standard mathematical order of operations,
01:17
we can achieve the results we expect.
01:21
Next, we'll take a look at setting up a rule to calculate the area of a wall.
01:26
First, we'll add an Inventor parameter to the model to hold the calculated square footage.
01:32
This will be used in our product definition form to display a read-only value.
01:38
In the Parameters tab of the product definition, we select Area to adopt it into the form.
01:45
This product definition has been set up to display the length and height in form messages as inches.
01:52
The message blocks have been collapsed, but can be expanded to view the contents.
01:58
Likewise, they can be collapsed again as needed.
02:03
Adding a block to make Area Read Only sets the block up for the next step of adding blocks to calculate it.
02:13
To create the calculation, the Area block is added to the canvas.
02:18
Then, the Length block is added, then copied and pasted using CTRL C and CTRL V on the keyboard.
02:26
Changing the block to Height, we're now ready to add the math Operations block and set it to Multiply.
02:33
Adding the Length and Height blocks to the Multiply block creates the Area calculation.
02:39
Using the right click External Inputs option,
02:42
wraps the block to fit in the canvas better.
02:45
And then a click of the form Update button shows the calculated area.
02:51
Next, we'll determine the diagonal measurement of the wall from corner to corner
02:55
by transforming the Pythagorean theorem to solve for length c.
03:01
An existing variable called Diagonal is used, and then the Square Root block is selected and snapped to it.
03:09
Next, the general Operations block is added twice,
03:13
and one instance is left to do addition, while the second is set to raise the value by a power of two.
03:21
Adding the Length Parameter block calculates the square value
03:25
and then the block is copied and the new block is changed to use the Height.
03:31
Both blocks are added to the Addition block to sum the results of both square parameter values.
03:37
A right click and a selection of External Inputs fits the block for easier reading.
03:45
Adding a Print block to pop up the value of Diagonal
03:48
allows the calculated corner to corner result to be displayed when the form is updated.
03:55
Getting the angles of the diagonal corners can be calculated using the Inverse Tangent Trigonometric block.
04:04
Here, we start by duplicating an existing connected block set.
04:09
Adding the Trigonometry math block and setting it to use the atan function
04:14
sets us up to quickly reuse existing code blocks from further up in the canvas.
04:20
Changing the variable from diagonal to one previously created, called angle A, completes this block rule.
04:29
Using Duplicate Connected to copy the entire block allows us to create a rule to solve for the remaining angle with ease and efficiency.
04:40
Updating the form shows us the results.
04:44
In summary, it's important to know that Math blocks evaluate as parenthetical groups
04:52
following standard order of operations.
04:55
There are numerous Math blocks to explore listed in the Math block library,
04:60
combining to allow for a rich set of mathematical calculations.
Step-by-step guide
Math code blocks contain mathematical blocks to perform a variety of operations. These include a Number constant block, a block with Operations of arithmetic, a block with Square Root and other common functions, a Trigonometry block, a Rounding block, a Remainder Of block, and a Constrain block to limit a number between a minimum and a maximum value.
When working with mathematical code blocks, it is important to understand the relationship between block grouping and the order of operations.
An arrangement of blocks is created with an intended result of 36, as shown in the calculation.
However, each block in the following block set acts as a grouped parenthetical calculation. When the code block is run, the result of the following configuration is 40.
The same blocks are rearranged and grouped to achieve the expected result of 36.
To set up a rule that calculates the area of a wall, first, add the Area parameter to the form:
- In Inventor, add a parameter for Area to hold the calculated square footage.
- In the Parameters tab of the Product definition, select Area to add it to the form.
- Click the Rules tab to view the added Area parameter.
The product definition shown below has already been set up to display the length and height in form messages as inches.
- If needed, to view the contents of a collapsed block, right-click and select Expand Block.
- To collapse it again, right-click and select Collapse Block.
To make the Area parameter read-only:
- Add a Nominal Wall Length parameter block. Set the parameter to Area and the function to readOnly.
- Finish the statement by adding a True False block with a value of true.
To create the Area calculation:
- Create another Area block.
- Add another Length block, then copy and paste it using CTRL+C and CTRL+V. Change the second parameter to Nominal Wall Length.
- Add an Operations math block to the Area block, set the operation to Multiply, and add the Length and Height parameter blocks to create the Area calculation.
- Right-click the Area block and select External Inputs to wrap the block.
- Click Update form.
The Area calculation displays in the form as a read-only value.
Next, to determine the diagonal measurement of the wall from corner to corner, transform the Pythagorean theorem to solve for length c.
- Add a Set to variable block and set it to Diagonal. Add and connect a Square Root Math block to the Diagonal block.
- Add two Operations Math blocks. Leave the first set to addition (+), and change the second to exponentiation (^), to raise the value by a power of 2.
- Add a Nominal Wall Length parameter to the Squared block. Duplicate this block to create the same block for the Height parameter.
- Add the Squared blocks to either side of the Addition block to sum the results of both squared parameter values.
- Right-click and select External Inputs to wrap the blocks to fit better in the canvas.
- Add the Squared blocks to the Diagonal Square Root block.
- To set the Diagonal result to print when the form is updated, below the Diagonal Square Root block, add a Print block and attach a Diagonal variable block.
- Click Update form.
A popup shows the Diagonal result.
The angles of the diagonal corners can be calculated using the Inverse Tangent Trigonometric block.
- Right-click the Diagonal Square Root block set and select Duplicate Connected. Remove the Square Root portion of the equation.
- Add a Trigonometry math block and set the function to atan.
- From the Area calculation, Duplicate the Length multiplied by Height block, add it to the Atan block, and change the Operation to Division.
- Change the Set To and Print variable blocks to a previously created variable, angle A.
- Right-click and select Duplicate Connected to copy the entire block. Set the drop-down to angle B, and then swap the Height and Length parameters.
- Click Update form.
The result for the Diagonal, along with the result for Angle A and Angle B display in the popup.
In summary, Math blocks evaluate as parenthetical groups following the standard order of operations. There are numerous Math blocks that can be combined to perform a variety of mathematical calculations.