• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualBrother Bob

Posted 17 August 2013 - 05:50 AM

Your sine wave probably has a too high frequency and when you sample at discrete points at too long intervals you get an aliasing effect. Your contant k_constant is probably way too high.

From what I understand from your code, m_points[i].[0] is the X-coordinate of the pixel you want the point to appear at. If that's the case, then the first thing to do is to normalize this parameter. If you divide it by WIDTH, which I assume is the width in pixels of your window, you'll get a parameter then spans from 0 to 1 along the full length of the window. If you then multiply by 2*pi, the parameter then spans from 0 to 2*pi over the full length of the window which corresponds to a full period.

Now that you have a parameter that spans one full period, you can easily tweak the frequency by multiplying again by the number of periods you want.

m_points[i].p[1] = amplitude * std::sinf(m_points[i].p[0]/WIDTH * 2*pi * periods);


Thus, if you want 5 periods across the screen, set period to 5.

### #1Brother Bob

Posted 17 August 2013 - 05:49 AM

Your sine way likely has a too high frequency and when you sample at discrete points at too long intervals you get an aliasing effect. Your contant k_constant is probably way too high.

From what I understand from your code, m_points[i].[0] is the X-coordinate of the pixel you want the point to appear at. If that's the case, then the first thing to do is to normalize this parameter. If you divide it by WIDTH, which I assume is the width in pixels of your window, you'll get a parameter then spans from 0 to 1 along the full length of the window. If you then multiply by 2*pi, the parameter then spans from 0 to 2*pi over the full length of the window which corresponds to a full period.

Now that you have a parameter that spans one full period, you can easily tweak the frequency by multiplying again by the number of periods you want.

m_points[i].p[1] = amplitude * std::sinf(m_points[i].p[0]/WIDTH * 2*pi * periods);


Thus, if you want 5 periods across the screen, set period to 5.

PARTNERS