A method of sending a single trapezoidal wave pulse involves using the Heisiside step function http://en.wikipedia.org/wiki/Heaviside_step_function
Use it if you want a βcleanβ mathematical way of representing this kind of function. Just create your function "in parts", multiply the first part by the body, which is "activated" when x = the beginning of your impulse. For the next fragment, first subtract the last function, then add the mathematical function of the new piece, multiply it by the adequate gravity function, and so on. This should end up with something like this (if you do not understand this, check out the Wikipedia article):
H(n) := (x >= n)?1:0; y := H(0)*(x) + H(1)*(-x + 1) + H(2)*(-(-x + 1) + (3-x));
However, for simplicity and efficiency, you can use the if statement. Consider a trapezoidal wave of 45 degrees with a constant unitary speed.
float trapezoidalWave(float x, float t) { float y; if ( x <= t + 1 ) { // 45 degree ascending line y = x - t; } else if ( x <= t + 2) { // horizontal line y = 1; } else if (x <= t + 3) { // 45 degree descending line y = t + 3 - x; } else { y = 0; } return y; }
If you need a "long wave", and not just one pulse, work with modules (%), if you do not need a time variable, just replace it with 0.
source share