## Problem with GDI & sin() (double & int problems)

### Problem with GDI & sin() (double & int problems)

sorry, i forgot the subject.. i am a lil bit tired and busy..

hello, i got a problem,
i want to draw the graph of mathematical functions like sin or cos or
parabel's (  f(x) = x^2 ).
i use a metafile object with class CPaintDC.

CPaintDC dc(GetDlgItem(IDC_SURFACE));

the point (0;0) is in the left up corner, thats ok....

i need it in the middle so i get the middle of the metafile object like
this:
int null_x, null_y;
CWnd *pSrf;
CRect SrfRect;
pSrf = GetDlgItem(IDC_SURFACE);
pSrf->GetClientRect (SrfRect);
null_x = SrfRect.right / 2;
null_y = SrfRect.bottom / 2;
// blah...

so,
now ill start to trying to draw the sin();

i tried it so:
int x,px,py;  // px and py are the points wich i use to draw..
px = null_x + x;
py = null_y - (sin(x * (pic / 180)));  // yeah, i know that i dont use
amplitude in this function, but i do in the real code!

so, now appears the problem,
sin() returns double value, thats ok, but
CDC::LineTo() requires int value!
so if i declare py as double, its not the solution!
when i give double value to CDC::LineTo() it would be converted to int.. so
its impossible to draw curve this way, becaue 0.5 as double will be 0 as
int!
so i tried to round the 0.5, but now i dont know why, i see not a sin curve,
i see a line...lol
i did my own function to round values:
its quiet easy and possible wrong.. but it works
int round(double x)
{
double b;
int c;
c  = x;
b = x - c;
if ( b < 0.5 )
return c;
else
return c + 1;

Quote:}

so, ill hope you can understand me and i hope that i dont forget something..
:-)
maybe one of you can help me, thank you !

(please dont tell me how bad my grammer and spelling is..thank you)

... Christian Meyer

### Problem with GDI & sin() (double & int problems)

Function sin(x) has really values in range(-1,1).
To have sin curve on the screen You should
draw not y=sin(x) but y=(int)(scale*sin(x)) where
scale is a variable of type double. The value
of variable scale depends on range of values of function
sin (it is 2) and y dimension of Your program
window. (If You want sin curve to fit in whole
window).

Quote:> sorry, i forgot the subject.. i am a lil bit tired and busy..

> hello, i got a problem,
> i want to draw the graph of mathematical functions like sin or cos or
> parabel's (  f(x) = x^2 ).
> i use a metafile object with class CPaintDC.

> CPaintDC dc(GetDlgItem(IDC_SURFACE));

> the point (0;0) is in the left up corner, thats ok....

> i need it in the middle so i get the middle of the metafile object
like
> this:
> int null_x, null_y;
> CWnd *pSrf;
> CRect SrfRect;
> pSrf = GetDlgItem(IDC_SURFACE);
> pSrf->GetClientRect (SrfRect);
> null_x = SrfRect.right / 2;
> null_y = SrfRect.bottom / 2;
> // blah...

> so,
> now ill start to trying to draw the sin();

> i tried it so:
> int x,px,py;  // px and py are the points wich i use to draw..
> px = null_x + x;
> py = null_y - (sin(x * (pic / 180)));  // yeah, i know that i dont use
> amplitude in this function, but i do in the real code!

> so, now appears the problem,
> sin() returns double value, thats ok, but
> CDC::LineTo() requires int value!
> so if i declare py as double, its not the solution!
> when i give double value to CDC::LineTo() it would be converted to
int.. so
> its impossible to draw curve this way, becaue 0.5 as double will be 0
as
> int!
> so i tried to round the 0.5, but now i dont know why, i see not a sin
curve,
> i see a line...lol
> i did my own function to round values:
> its quiet easy and possible wrong.. but it works
> int round(double x)
> {
>  double b;
>  int c;
>  c  = x;
>  b = x - c;
>  if ( b < 0.5 )
>   return c;
>  else
>   return c + 1;
> }

> so, ill hope you can understand me and i hope that i dont forget
something..
> :-)
> maybe one of you can help me, thank you !

> (please dont tell me how bad my grammer and spelling is..thank you)

> ... Christian Meyer

--
Stanislaw Kozlowski, Poland

Sent via Deja.com http://www.deja.com/

Hi,

Can you tell me what does the following do:

int initConsole(int& Width, int& Height, int& FullScreen, int& Flags,
Screen* S)

I know it's a prototype and stuff like that. But is it anything special?
Does it replace main() in a program? If it does what does it do? Like,
what's suppose to be in it and what does the function suppose to do?