Graphics data conversions

1h1a0m at kuhub.cc.ukans.edu 1h1a0m at kuhub.cc.ukans.edu
Wed Apr 24 03:23:45 AEST 1991


In article <14422 at ccncsu.ColoState.EDU>, steves at longs.LANCE.ColoState.EDU (Steve Smith) writes:
> 
> Has anyone had experience with graphing data points in Turbo C?  
> I'm trying to get data (both neg and pos) to fit within the 
> getmaxx(); and getmaxy(); of a screen.  I need a routine that 
> converts the data points into a useable scale.  I'm using just
> the lineto(x,y); and moveto(x,y); functions to plot points.
> 
> Any help would be appreciated!
> 
> S Smith
> CSU Fort Collins, Colorado


OK, here's some C code to get you started:

/* .... */

    int xmin, xmax, ymin, ymax, screen_x, screen_y;
    double data_xmin, data_xmax;
    double data_ymin, data_ymax;
    double data_x, data_y;

    data_x = 40.0;
    data_xmin = -20.0;    /* lower limit of your x data */
    data_xmax =  80.0;    /* upper limit of your x data */

    xmin = 0;             /* TC screen x min */
    xmax = getmaxx();     /* TC screen x max */

    screen_x = (int) (
                       ( data_x    - data_xmin ) /
                       ( data_xmax - data_xmin ) *
                       (double) ( xmax - xmin )
                     );

/* .... */
/* similar code for y-coordinate */
/* .... */

    lineto( screen_x, screen_y );

/* .... */


This code assumes that the entire screen is used for plotting.
If you want to establish a subplot area you must modify the
scaling procedure to incorporate offsets in the x and y directions.

Good luck

A. Montes
Univ. of KS



More information about the Comp.lang.c mailing list