Re: CPoint Help
- From: "Frank Hickman [MVP]" <fhickman_NOSP@xxxxxxxxxxxxxxx>
- Date: Wed, 27 Apr 2005 02:44:49 -0400
In addition to Scott's reply...
"confusedinc" <confusedinc@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BD69CA56-4369-4870-87BA-7AEE39B93A7E@xxxxxxxxxxxxxxxx
>I cannot get my CPoint point[8] array to draw lines based on the criteria
> below. I have confused myself to no end. Stuck on this problem. Program
> will
> draw lines without the array, however, I would like to be able to change
> code
> to use the array instead. I'm using VC++ 6.0.
> Thanks!
> Here is what I have so far:
>
> void CProject5View::OnDraw(CDC* pDC)
> {
> double PI = 3.1415926535;
> int x;
> int y = 0;
> int i = 0;
>
> double dStep = (PI * 2) / m_iSamples;
> double dResult = i * dStep;
The multiplication in this initialization is unneeded since you have
initialized i to zero, the result would always be zero.
>
> pDC->MoveTo(60, 200);
> pDC->LineTo(60, 400);
> pDC->LineTo(550, 400);
> pDC->MoveTo(60, 400);
> pDC->LineTo(60, 600);
>
> // I wish to use this array to draw my lines instead of the code that
> follows //
> see sin and cos case statements below
>
>
> CPoint point[8];
> point[0] = (PI/4 * x, 0.707 * y);
> point[1] = (PI/2 * x, 1 * y);
> point[2] = ((3*PI)/4 * x, 0.707 * y);
> point[3] = (PI * x, 0 * y);
> point[4] = ((5*PI)/4 * x, -0.707 * y);
> point[5] = ((3*PI)/2 * x, -1 * y);
> point[6] = ((7*PI)/4 * x, -0.707 * y);
> point[7] = (2*PI * x, 0 * y);
>
x is uninitialized and y is initialized to zero. What are you attempting
here? What are your calculations for? These values will not draw a sine
wave like your for loop does...
>
> int PtX = 60;
> int PtY = 400;
> int xLine = 500 / m_iSamples;
> int yLine = xLine;
>
> switch (m_Graph) {
> case Sin:
>
> pDC->MoveTo(PtX,PtY);
> for(i=0; i<=m_iSamples; i++) {
> dResult = i*dStep;
> dResult = sin(dResult);
> dResult = 200 * dResult;
> y = (int)dResult;
> y = PtY - y;
> x = PtX + i * xLine;
> pDC->LineTo(x,y);
>
> }
> break;
>
> case Cos:
> pDC->MoveTo(PtX, PtY - 200);
> for(i=0; i<=m_iSamples; i++) {
> dResult = i*dStep;
> dResult = cos(dResult);
> dResult = 200 * dResult;
> y = (int)dResult;
> y = PtY - y;
> x = PtX + i * xLine;
> pDC->LineTo(x,y);
>
> }
> break;
>
> }
> }
>
This will do exactly what your for loop does but using a CPoint array...
// Draw the vertical bar line...
pDC->MoveTo( 60, 200 );
pDC->LineTo( 60, 600 );
// Draw the horizontal line bar...
pDC->MoveTo( 60, 400 );
pDC->LineTo( 550, 400 );
const double PI= 3.1415926535;
int x= 0; // No longer needed...
int y= 0; // No longer needed...
int i= 0;
double dStep= (PI * 2) / m_iSamples;
double dResult= i * dStep;
// Point where drawing will commence...
int PtX= 60;
int PtY= (m_Graph == Sin) ? 400 : 200;
int xLine= 500 / m_iSamples;
// Start where the vertical and horizontal lines intersect...
pDC->MoveTo( PtX, PtY );
CPoint pt[9]; // Assumes that m_iSamples == 8
for( i= 0; i <= m_iSamples; i++ )
{
dResult= i * dStep;
dResult= (m_Graph == Sin) ? sin( dResult ) : cos( dResult );
dResult= 200 * dResult;
pt[i].y= (int)dResult;
pt[i].y= PtY - pt[i].y;
pt[i].x= PtX + i * xLine;
// Draw the line segment...
pDC->LineTo( pt[i].x, pt[i].y );
}
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
.
- References:
- CPoint Help
- From: confusedinc
- CPoint Help
- Prev by Date: Passing DB connection object between 2 Process
- Next by Date: Re: multiline Static
- Previous by thread: Re: CPoint Help
- Next by thread: Moving a Pasting Bitmap
- Index(es):
Relevant Pages
|