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

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

Post by Christian Meye » Mon, 02 Oct 2000 04:00:00



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)

Post by Stanislaw Kozlowsk » Thu, 05 Oct 2000 04:00:00


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/
Before you buy.

 
 
 

1. int initConsole(int& Width, int& Height, int& FullScreen, int& Flags,

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?

Thnx in advance

2. Vuescan and Slide film types, E6 versus E6 Low Satrtn

3. class(int& a,b,c) => class(int& a, int& b, int& c).

4. 3rd party disks for Onyx ?

5. &#1082;&#1085;&#1080;&#1075;&#1072; c\&#1089;++

6. MSN 5.1 reboots my computer while dialing

7. &&& Moles and Mazes &&&

8. A3000 + Z3 Memory Cards

9. &#1605;&#1579;&#1601;&#1601;&#1588;&#1602;

10. Differenze between const int& and int const& ???

11. What is int &volatile r; [Was: What is int &const r;]

12. const int& or int const&

13. &#1091;&#1095;&#1077;&#1073;&#1085;&#1080;&#1082; &#1087;&#1086; &#1089;\&#1089;++