Graphing a sine/cosine/tan curves in C???

This is a discussion on Graphing a sine/cosine/tan curves in C??? within the C Programming forums, part of the General Programming Boards category; http://www.sci.brooklyn.cuny.edu/~sd.../Program6.html the link above are specifications to making a so called "simple" program, but how would this be done? especially ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    Question Graphing a sine/cosine/tan curves in C???

    http://www.sci.brooklyn.cuny.edu/~sd.../Program6.html

    the link above are specifications to making a so called "simple" program, but how would this be done? especially the graphing of sin, cos and tan?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    graph(sin,0.0,10.0,20);
    You create a loop that goes from 0.0 to 10.0 (the example in the link I think got it wrong by saying 0.0 to 20.0) in increments of (hi-lo)/(num of points) so:

    Code:
    void graph( double (*func)(double),double lo,double hi, int number )
    {
        double pt;
        double inc = (hi-lo)/number;
    
        for( pt = lo; lo <= hi; pt += inc )
        {
            /* Call the function for the given pt value, you would need to
            do something with the return value, i.e. store it in an array perhaps
            for later use */
            func(pt);
        }
    
    }
    Once you've got all the values stored in an array, you need to normalize them based on the height of the screen display. Then it is a simple matter of going through the stored values in the array and outputting a symbol at the appropriate height based on the normalized value.
    Last edited by hk_mp5kpdw; 12-13-2005 at 05:28 AM.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    13
    how would you print an asterisk based on the height?

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    probably create a 2d char array:-

    Code:
    [ ][ ][ ][ ][ ][ ][ ]
    [ ][ ][ ][ ][ ][ ][ ]
    [ ][ ][ ][ ][ ][ ][ ]
    [ ][ ][ ][ ][ ][ ][ ]
    [ ][ ][ ][*][ ][ ][ ]
    [ ][*][*][ ][*][*][ ]
    [ ][*][ ][ ][ ][*][ ]
    Then print out the 2d array using a nested for loop.

    How you gets the stars into the array will be of course your main problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bezier Curves where y = f(x)
    By thetinman in forum Game Programming
    Replies: 11
    Last Post: 12-27-2008, 09:21 AM
  2. Default intersection of two curves on unit sphere
    By Zeeshan in forum Game Programming
    Replies: 1
    Last Post: 06-23-2008, 11:30 AM
  3. Open source graphing / plotting library?
    By sysop in forum C Programming
    Replies: 2
    Last Post: 06-05-2007, 12:20 PM
  4. Graphing Calculator..
    By willc0de4food in forum Windows Programming
    Replies: 12
    Last Post: 09-26-2005, 06:57 PM
  5. Graphing Calculators
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-17-2003, 07:23 AM

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