Showing a line on the monitor. quick question

This is a discussion on Showing a line on the monitor. quick question within the Game Programming forums, part of the General Programming Boards category; Im not sure if this goes in here, but this is for a graphics programming class. Feel free to move ...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    141
    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, 05:58 AM
  3. Showing Line Numbers in MSVC++
    By drdroid in forum Windows Programming
    Replies: 1
    Last Post: 01-09-2003, 02:23 PM
  4. command-line network monitor
    By rotis23 in forum Linux Programming
    Replies: 1
    Last Post: 11-12-2002, 11:49 AM
  5. TV and Monitor question
    By Korn1699 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-07-2002, 12:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21