20
$\begingroup$

How does the math node do calculations with a specific operation:

enter image description here

the usual operations of add,subtract, multiply and divide are quite understandable and are(empirically) very similar to some of the operations in MixRGB node. But, how do the operations such as Sine, Power, Logarithm, Minimum, Maximum, Modulo, Round, etc,.. interpret with the values. How can we visualize this in realtime?

$\endgroup$
2
  • 3
    $\begingroup$ do you want to see the math behind them or visualize them $\endgroup$
    – Chebhou
    Commented Jan 17, 2016 at 12:13
  • 1
    $\begingroup$ actually both, so the output would be much more predictable. $\endgroup$
    – bzal
    Commented Jan 17, 2016 at 23:12

2 Answers 2

40
$\begingroup$

Here is a list of the mathematical equivalents of each operation.

  • Add: Out = Value1 + Value2.
  • Subtract: Out = Value1 - Value2.
  • Multiply: Out = Value1 * Value2.
  • Divide: Out = Value1 / Value2.
  • Sine: Out = Sin(Value1).
  • Cosine: Out = Cos(Value1).
  • Tangent: Out = Tan(Value1).
  • Arcsin: Out = Sin⁻¹(Value1).
  • Arccosine: Out = Cos⁻¹(Value1).
  • Arctangent: Out = Tan⁻¹(Value1).
  • Power: Out = Value1 ^ Value2.
  • Logarithm: Out = log(Value2, Value1).††
  • Minimum: Out = Smaller Value of (Value1, Value2).
  • Maximum: Out = larger value of (Value1, Value2).
  • Round: Out = Value1 rounded to nearest integer.
  • Less Than: Out = 1 if Value1 < Value2, else 0'
  • Greater Than: Out = 1 if Value1 > Value2, else 0'
  • Modulo: Out = Value1 (mod Value2).

Note that some operations use only the first input, in such cases the second input is ignored completely.

†. All trigonometric functions use radians.
††. log(x, y) = the logarithm of x to the base y.
‡. x mod y = the remainder when x is divided by y.

$\endgroup$
7
  • $\begingroup$ Is the second input value useless for trigonometric functions? $\endgroup$
    – bzal
    Commented Jan 17, 2016 at 23:12
  • 1
    $\begingroup$ @bzal Yes, see edit. $\endgroup$
    – PGmath
    Commented Jan 18, 2016 at 0:57
  • $\begingroup$ what is the clamp for? $\endgroup$
    – bzal
    Commented Jan 18, 2016 at 5:02
  • $\begingroup$ clamp keeps the result between 0 and 1 $\endgroup$
    – sambler
    Commented Jan 18, 2016 at 7:02
  • $\begingroup$ It doesn't work, for example Cosine with a value of 90 should give me 0 I have tried with a translate node with X at 0, I have attached the node and the image moves (more visible with a multiply node in between). $\endgroup$ Commented Mar 8, 2018 at 20:16
13
$\begingroup$

To supplement PGmath's answer:

It is worth noting that the math is calculated a bit differently than you might think. It has to do with limitations of storing and representing floating point numbers (reals) in a computer (in binary format).

For the same reasons you cannot represent 1/3 in decimal exactly (it is 0.333...) you cannot represent exactly (for example) 1/10 in binary (but it is easy in decimal as 0.1).

The decimal floating-point numbers you enter are only approximated by the binary floating-point numbers actually stored in the machine.

This can result in some surprises. You can see what the number stored in machine actually is like this in a Python Console:

from decimal import Decimal
Decimal(2.675) = 2.67499999999999982236431605997495353221893310546875

So when rounding this number to 2 decimal places it will result in 2.67 instead of 2.68 you expect.

When building large nets of Math Nodes such "errors" can lead to a butterfly effect causing big differences in the end on the output.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .