We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › sinus discontinuity - update
Page Index Toggle Pages: 1
sinus discontinuity - update (Read 870 times)
sinus discontinuity - update
Nov 3rd, 2006, 10:48am
 
Hi,

I'm coverting a sinus to a basic binary pattern. This works fine, only for a large wavelength.
Drawing a smaller sinus results in a strange pattern. I would expect greenpixel-whitepixel-greenpixel-whitepixel..., but that's not what's happening...

How come the sinus isn't continuous for a wavelength of 2 pixels?

http://www.wereldopener.nl/sinus/index.html
Re: sinus discontinuity - update
Reply #1 - Nov 4th, 2006, 12:33am
 
I beleive the answer is rounding.  Once you get to the limit of screen resolution the results are kinda unpredictable.  If your wavelength is exactly 2 pixels, it will show black,white,... but if your wavelength is even 1.9999 pixels, the results could be something else.

If you had an infinite resolution display, it would always look perfect.
Re: sinus discontinuity - update
Reply #2 - Nov 4th, 2006, 2:43pm
 
Thank you for replying...

Your answer triggered a thought: could it be a sampling problem as well?
If I sample just before or just after Pi/2 instead of right on target, it would also explain this interference.

Re: sinus discontinuity - update
Reply #3 - Nov 7th, 2006, 10:00am
 
Looks like a float to int conversion truncation error to me, perhaps the way your rendering your patterns? I'd have to see the code to be sure.

Jack
Re: sinus discontinuity - update
Reply #4 - Nov 7th, 2006, 10:19am
 
Yep just checked out your programs source, just change maxline and mySlider to floating point values and you'll get the output you expect, the problem is the remainder is being dropped off in the devide your doing of the two ints.

Another option is to cast the values but that is slower.

Jack
Re: sinus discontinuity - update
Reply #5 - Nov 8th, 2006, 12:25pm
 
Jack, thanks for crawling through my code.

I'm wondering whether the integers (slider & maxline) are the only problem.

I've scaled up the amplitude and added the following to illustrate

   line(pixnum, (myheight/2)+7*myheight, pixnum, (myheight/2)+7*myheight - (myheight/3)*(sin(pixnum*(TWO_PI/(myheight/12)))));

This function doesn't use the 2 integers. The corresponding sinus however isn't a continuous pattern either.

I also tried your suggestion, but changing the slider & maxline to float requires some additional tweaking of the scrollbarcode. I believe it's wise to look at the basic ;) problem with the sinus, before tweaking the scrollbar to match my wishes...

Any idea?



//pieter
Page Index Toggle Pages: 1