Thread: Showing a line on the monitor. quick question

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    144

    Showing a line on the monitor. quick question

    Im not sure if this goes in here, but this is for a graphics programming class. Feel free to move it mods if need be

    The code below draws a straight line on the screen. When I change the FOR LOOP VARIABLE, th(theta), to go from 0 to 2pi (i.e. 2*3.15159) it displays 7 dots on the screen.

    When I change theta to 4*pi it displays 13 dots on the screen.

    The question is, shouldn't it still display 7 dots on the screen because cos is periodc. So the same values are repeated again

    Code:
                  float y;
    	float th;
    	float x;
    	
    
    	for(th=0;th<=2*3.14159;th++)
    	{
    		
    		x= 100 + 80*cos(th);
    		y= 70; 
    		pDC->SetPixel(x,y,RGB(0,0,255));
    	}
    Last edited by bos1234; 03-21-2012 at 04:36 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > The question is, shouldn't it still display 7 dots on the screen because cos is periodc. So the same values are repeated again
    It might, if you incremented th by some fraction of PI, and not by 1.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    144
    thanks for your reply. Yes i thought about it. You are right, since im increasing by 1, it will churn out a new value everytime

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-08-2011, 06:26 AM
  2. Quick, newbie question: Multiple line string
    By crummy in forum C# Programming
    Replies: 2
    Last Post: 03-10-2005, 06:58 AM
  3. Showing Line Numbers in MSVC++
    By drdroid in forum Windows Programming
    Replies: 1
    Last Post: 01-09-2003, 03:23 PM
  4. command-line network monitor
    By rotis23 in forum Linux Programming
    Replies: 1
    Last Post: 11-12-2002, 12:49 PM
  5. TV and Monitor question
    By Korn1699 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-07-2002, 01:44 PM