My brain doesn't work right now: What's the formula for the $n$th vertex of a discretized sine wave?

53 Views Asked by At

So far I have:

$$ A \sin(2\pi f ? + \phi) $$

where $f$ is cycles per second, and $\phi$ is in seconds. If I'd like to approximate the sine wave with $N$ points per cycle, and I want to draw $C$ cycles of it which could be fractional, how do I complete the above formula? And by that I mean:

def placeSineWaveFunc(self, freq, amp, phase, cycles, pointsPerCycle):
    polyline = self.polyline
    numPoints = int(cycles * pointsPerCyle + 0.5)
    for k in range(0, numPoints):
         t = ????
         polyline.addPoint(QPointF(t, amp * math.sin(2*PI*freq*t + phase))
    # The rest of my placer method

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

I think I got it! Thanks @Michael.

    def placeSineWaveFunc(self, freq, amp, phase, cycles, pointsPerCycle):
    polyline = self.polyline
    numPoints = int(cycles * pointsPerCycle + 0.5) + 1
    for n in range(0, numPoints):
        t = n / pointsPerCycle
        polyline.addPoint(QPointF(t, amp * math.sin(2*math.pi*freq*t + phase)))

\o/