plot

Discussion in 'C Programming' started by Umesh, Aug 28, 2007.

  1. Umesh

    Umesh Guest

    I've not used graphics.h before. How can I plot a function say
    y=sin(x) ?
    Umesh, Aug 28, 2007
    #1
    1. Advertising

  2. In article <>,
    Umesh <> wrote:
    >I've not used graphics.h before. How can I plot a function say
    >y=sin(x) ?


    Sorry, graphics.h is not part of the C programming language.

    There are a number of completely different graphics.h around.
    You need to consult a reference suitable for your implementation.


    Poking around a moment, I see an old example that might still
    be of value for you. Or maybe not, considering all the different
    graphics.h around.

    http://www.mycplus.com/Programming-News-Articles.asp?NewsID=33

    --
    Prototypes are supertypes of their clones. -- maplesoft
    Walter Roberson, Aug 28, 2007
    #2
    1. Advertising

  3. "Umesh" <> wrote in message
    news:...
    > I've not used graphics.h before. How can I plot a function say
    > y=sin(x) ?
    >

    It's a platform-specific header.

    I've no idea how it works, but presumably you will need to intialise a
    graphics display. Then there will almost certainly be a function called
    something like plotxy(). It may take floats but will probably take integers.

    Your x axis will go from -PI to + PI, whilst your y axis will go from -1 to
    +1. However to really see the shape of the function, keep the scales the
    same, that's why we measure angles in radians.

    So all you need to do is maintain a double x, and take pixel steps from -PI
    to +PI. Call sin() to get y. Then convert from the mathematical coordinates
    to the pixel coordinates, making x = 0, y = 0 the centre pixel of the
    display, and call the plot function.


    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Aug 28, 2007
    #3
  4. Umesh

    Joe Wright Guest

    Walter Roberson wrote:
    > In article <>,
    > Umesh <> wrote:
    >> I've not used graphics.h before. How can I plot a function say
    >> y=sin(x) ?

    >
    > Sorry, graphics.h is not part of the C programming language.
    >
    > There are a number of completely different graphics.h around.
    > You need to consult a reference suitable for your implementation.
    >
    >
    > Poking around a moment, I see an old example that might still
    > be of value for you. Or maybe not, considering all the different
    > graphics.h around.
    >
    > http://www.mycplus.com/Programming-News-Articles.asp?NewsID=33
    >

    I'm sure you are trying to be helpful but any random graphics.h header
    is likely to be utterly useless. A given header might have a function
    prototype. The actual function must be in a library linked as we build
    the executable. The header and the library are married.

    If your implementation doesn't have a conio.h header for example,
    copying one from Borland or other system may not give you getch() or
    clrscr() or whatever. The functions are in the library, not the header.

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Aug 28, 2007
    #4
  5. In article <>,
    Joe Wright <> wrote:
    >Walter Roberson wrote:
    >> In article <>,
    >> Umesh <> wrote:
    >>> I've not used graphics.h before. How can I plot a function say
    >>> y=sin(x) ?


    >> Poking around a moment, I see an old example that might still
    >> be of value for you. Or maybe not, considering all the different
    >> graphics.h around.


    >> http://www.mycplus.com/Programming-News-Articles.asp?NewsID=33


    >I'm sure you are trying to be helpful but any random graphics.h header
    >is likely to be utterly useless. A given header might have a function
    >prototype. The actual function must be in a library linked as we build
    >the executable. The header and the library are married.


    I did not suggest that Umesh copy a graphics.h file from somewhere.

    The article referenced shows an actual example of graphics
    functions in use in Windows, -likely- based upon the old Borland
    graphics library. The Borland graphics library is the one that
    came up most often for graphics.h and several more modern implementation
    libraries I found in my poking appear to deliberately retain
    compatability with the Borland facilities. And we've encountered
    Umesh often enough to know he is using Windows of some kind.

    Notice that my wording was that it was "an old example", rather
    than any kind of wording suggesting that I was pointing to a
    copy of graphics.h or pointing to an implementation library.
    "example" -- something to be examined and studied for learning
    purposes.
    --
    Programming is what happens while you're busy making other plans.
    Walter Roberson, Aug 28, 2007
    #5
  6. Umesh

    user923005 Guest

    On Aug 28, 1:20 pm, Umesh <> wrote:
    > I've not used graphics.h before. How can I plot a function say
    > y=sin(x) ?


    In the C language (all by itself) you can plot a character based
    graph.

    If you want to make pretty pictures, you will need to use a graphical
    extension to the language.

    PHIGS is one standards based extension.
    XWindows is another.
    GKS is another.
    CGM is another.

    Or you can use something like OpenGL or DirectX, which are proprietary
    but well accepted.
    user923005, Aug 28, 2007
    #6
  7. Umesh

    user923005 Guest

    On Aug 28, 1:20 pm, Umesh <> wrote:
    > I've not used graphics.h before. How can I plot a function say
    > y=sin(x) ?


    If you are interested in drawing pictures, you might try
    news:comp.graphics.algorithms.
    Of course, you will read their FAQ before posting.
    user923005, Aug 29, 2007
    #7
  8. Malcolm McLean wrote:
    >
    > "Umesh" <> wrote in message
    > news:...
    > > I've not used graphics.h before. How can I plot a function say
    > > y=sin(x) ?
    > >

    > It's a platform-specific header.
    >
    > I've no idea how it works, but presumably you will need to intialise a
    > graphics display. Then there will almost certainly be a function called
    > something like plotxy(). It may take floats but will probably take integers.

    [...]

    Not necessarily, although that's probably what the OP wants.

    Way (way, way!) back, I would plot things like that by placing
    the X axis down the page, and draw the X axis with "|" and place
    a "*" along the Y axis, using spaces to place the characters as
    needed.

    --------*--------
    | *
    | *
    | *
    | *
    | *
    | *
    *
    * |
    * |
    * |
    * |
    * |
    * |
    *

    Pure text, and easily done in pure ANSI C. (Although it does
    depend on a monospaced output device.)

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:>
    Kenneth Brody, Aug 29, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Wieser

    how to plot audio input?

    Peter Wieser, May 10, 2004, in forum: Java
    Replies:
    0
    Views:
    380
    Peter Wieser
    May 10, 2004
  2. Boris Glawe
    Replies:
    1
    Views:
    8,557
    Kevin Goodsell
    Aug 25, 2003
  3. magiczla
    Replies:
    0
    Views:
    36,011
    magiczla
    Aug 30, 2003
  4. Sloan

    How to plot Sin wave ?

    Sloan, Aug 3, 2004, in forum: C++
    Replies:
    3
    Views:
    4,960
    Uwe Schnitker
    Aug 5, 2004
  5. Dr. Colombes
    Replies:
    1
    Views:
    1,031
    John Hunter
    Feb 10, 2005
Loading...

Share This Page