5
$\begingroup$

Reading through the math node docs, I came across a math function named "ping-pong".

The docs state that ping-pong does the following

The output value is moved between 0.0 and the Scale based on the input value.

What in the world does that mean? Can anyone tell me what the actual ping-pong function is? What input values lead to an output of 0, and what input values lead to an output of "scale"?

$\endgroup$

1 Answer 1

10
$\begingroup$

It's a positive symmetrical triangle-wave, amplitude Scale, period 2 * Scale, 0 at 0.

enter image description here

Here's the function illustrated with 'Scale' (from the bottom up) set to 1, 0.5, and 0.333.

These planes are 8 units across, and 2 up, 0 at center.

You could roll your own like this:

PingPong(Value) = Scale - abs( (abs(Value) % (2*Scale)) - Scale)

..but someone else might come up with a neater way.. :)

edit: Indeed they have :) thanks to @Nikolai for:

Scale - abs(Value % (2*Scale) - Scale )

You could wrap up the node like this to give more intuitive inputs?

enter image description here

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ great illustrative answer, thank you. Glad I asked, because that's not at all what I imagined it would be. I expected a square-wave type function. $\endgroup$
    – rothloup
    Commented Jul 12, 2020 at 15:13
  • 1
    $\begingroup$ @rothloup Thanks! .. Keep the graphing trick in your back pocket.. you can visualise the other functions, and your own combinations. $\endgroup$
    – Robin Betts
    Commented Jul 12, 2020 at 16:21
  • $\begingroup$ > ..but someone else might come up with a neater way.. :) You can remove the inner abs: Start with abs(input), then flip it with a negative sign: -abs(input) Then add scale to move it up: scale - abs(input) Then get it in range: scale - abs(input%2*scale) Finally shift the peak so that it sits at scale: scale - abs(input%(2*scale)-scale) $\endgroup$
    – Nickolai
    Commented Oct 28, 2023 at 19:23
  • $\begingroup$ @Nickolai hehe .. I love it when that happens :) Will insert with a credit, and leave the challenge up, when tested. $\endgroup$
    – Robin Betts
    Commented Oct 29, 2023 at 8:51

You must log in to answer this question.

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