hello,

the following code should create a series of random points in green that approach a circle; a bounding circle in purple with a maximum radius considering all the points. I can't get the bounding circle to display. Help !!


Here is the code:

void DrawStuff() {
COLORREF green = RGB(0, 255, 0); // green color to draw with
COLORREF purple = RGB(255, 0, 255); // purple color to draw with

char str[32]; // string to store user input
int numPoints; // user input
int *xPts, *yPts; // ptrs for dynamic array of x,y coordinates
int i; // loop and point variables
RECT rect; // rectangle for the output window
int xMin, wdRect, yMin, htRect; // min rectangle coords and rect width & height
int xSum, ySum, xAvg, yAvg;
double rMax, temp, tempDist;
double sqrt(double x);


// clear the scene and add an axis
PGraphics->ClearScene(RGB(0, 0, 0));
PGraphics->AddAxis(RGB(150, 150, 150), 10);

// get the rectangle info for this window
GetClientRect(HOutput, &rect);
wdRect = rect.right - rect.left;
xMin = -wdRect / 2;
htRect = rect.bottom - rect.top;
yMin = -htRect / 2;

// get the user input from the edit boxes and
// convert string input to integer
GetDlgItemText(HDialog, IDC_EDIT_NUMPOINTS, str, 32);
numPoints = atoi(str);

// allocate and initialize the arrays with random point values
xPts = new int[numPoints];
yPts = new int[numPoints];
for (i = 0; i < numPoints; i++) {
// keep points within range -wd/4..+wd/4, -ht/4..+ht/4 so
// bounding circle won't get too large
xPts[i] = wdRect/4 - rand() % (wdRect/2);
yPts[i] = htRect/4 - rand() % (htRect/2);
Circle(xPts[i], yPts[i], 1, green);
}

// draw the points
PGraphics->Draw();
// Find the avg of all the points.
//This will be the bounding circle center.

xSum = 0;
ySum = 0;
for (i = 0; i < numPoints; i++)
{
xSum += xPts[i];
ySum += yPts[i];
}
xAvg = xSum / numPoints;
yAvg = ySum / numPoints;



for (i = 0; i < numPoints; i++) {
rMax = 0;
int x = (xAvg - xPts[i]);
int y = (yAvg - yPts[i]);
temp = (x * x) + (y * y);
tempDist = sqrt(temp);

if (rMax < tempDist){
rMax = tempDist;
}
}


Circle(xAvg, yAvg, 1, purple); // to draw the center

Circle(xAvg, yAvg, rMax, purple); // to draw the bounding circle

// draw the points
PGraphics->Draw();


// free up the allocated memory for the points
delete[] xPts;
delete[] yPts;
}