Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!caen!kuhub.cc.ukans.edu!1h1a0m From: 1h1a0m@kuhub.cc.ukans.edu Newsgroups: comp.lang.c Subject: Re: Graphics data conversions Message-ID: <1991Apr23.122346.29929@kuhub.cc.ukans.edu> Date: 23 Apr 91 17:23:45 GMT References: <3635@loria.crin.fr> <14422@ccncsu.ColoState.EDU> Distribution: usa Organization: University of Kansas Academic Computing Services Lines: 53 In article <14422@ccncsu.ColoState.EDU>, steves@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