
October 8th, 2001, 03:05 AM
#1
Store all pixel from a circle in an array?
Hi,
how can I store all pixel from a circle/ellipse in an array?
Thank you for your help

October 8th, 2001, 05:09 AM
#2
Re: Store all pixel from a circle in an array?
#include "math.h" // need sin/cos functions
#define _PI (2*asin(1)) // define PI
#define STEP_SIZE 360 // number of points to store
#define XIndex 0
#define YIndex 1
double array[2][STEP_SIZE];
// or
// CPoint ptArray[STEP_SIZE];
double radius = 50;
CPoint ptC(200,200); // Centre point
double step = (2* _PI) / STEP_SIZE;
for (int index = 0; index < STEP_SIZE; index ++)
{
double theta = index * (2* _PI) / STEP_SIZE;
array[XIndex][index] = (radius * cos(theta)) + ptC.x;
array[YIndex][index] = (radius * sin(theta)) + ptC.y; // for ellipse use a different value for the radius
// if we have a DC to test... Plot the pixel on the graphics screen
// add 0.5 to assist rounding to nearest integer
dc.SetPixel((int)(array[XIndex][index]+ 0.5), (int)(array[YIndex][index]+0.5),RGB(255,0,0));
}
Hope this helps
Eugene Gill
Please take the time to reply and/or rate this answer if you found it useful.
Other readers will then be better informed.

October 8th, 2001, 01:45 PM
#3
Re: Store all pixel from a circle in an array?
First of all thank you for your help!
I think, I've expressed me wrong.
I want to store all pixel from the area of the circle in an array, not only the points from the circumference.
If you could help me further, it would be very nice.
Thanks for your time

October 8th, 2001, 01:54 PM
#4
Re: Store all pixel from a circle in an array?
Why?
It's not very efficient.
Hope this helps
Eugene Gill
Please take the time to reply and/or rate this answer if you found it useful.
Other readers will then be better informed.

October 8th, 2001, 05:32 PM
#5
Re: Store all pixel from a circle in an array?
If your question relates to finding the pixels inside of a circle, it is a pretty ugly process.
Calculate 2 rectanges. An outer rectange
left = center.x  radius;
top = center.y  radius;
width = radius * 2;
height = radius * 2;
Then calculate the bigest rectangle that fits inside the circle.
left = center.x = cos(PI/2) * radius;
etc.
simply scan all pixels inside the inner rectangle.
For each pixel in the outer rectangle that is not in the inner rectange, calculate its distance from the center sqrt(x*x + y*y) If its less than the radius its inside the circle.
Hope this helps.

October 9th, 2001, 09:30 AM
#6
Re: Store all pixel from a circle in an array?
I want to calculate the average RGBvalue of the circle and pie of the circle.
Have you got another idea?

October 9th, 2001, 09:35 AM
#7
Re: Store all pixel from a circle in an array?
Thank you for help,
do you even knpw how to destinate the pixel (inclusively the content) of a pie of the circle.
The 360 pixel of the circumference I calculated before.

October 9th, 2001, 10:16 AM
#8
Re: Store all pixel from a circle in an array?
Better off storing the RGB values than the pixels then.
What about this? (DISCLAIMER, untested!)
class Circle
{
public:
int m_xCenter;
int m_yCenter;
double m_Radius;
BOOL PtInCircle(int x, int y);
};
BOOL Circle::PtInCircle(int x, int y)
{
// Determine x, y with centre at 0,0
double absX = x  m_xCenter / 2;
double absY = y  m_yCenter / 2;
// Apply formula
return ((absX * absX) / (m_Radius * m_Radius) + (absY * absY) / (m_Radius * m_Radius) <= 1);
}
Circle c1;
c1.m_xCenter = 100;
c1.m_yCenter = 100;
c1.m_Radius = 20;
int left = int (c1.m_xCenter  m_Radius  0.5) // rounded down
int right = int (c1.m_xCenter + m_Radius + 0.5) // rounded up
int top = int (c1.m_yCenter  m_Radius  0.5) // rounded down
int bottom = int (c1.m_yCenter + m_Radius + 0.5) // rounded up
double r = 0;
double g = 0;
double b = 0;
int pointCount = 0;
for (int x = left; x <= right; x++)
{
for (int y = top; x <= bottom; x++)
{
// is pixel in circle?
if c1.PtInCircle(x,y)
{
// get RGB values
pointCount++;
COLORREF rgbV = dc.GetPixel(x,y);
r+= GetRValue(rgbV);
g+= GetGValue(rgbV);
b+= GetBValue(rgbV);
}
}
}
r = int(0.5+ (r/pointCount)); // round to nearest int
g = int(0.5+ (g/pointCount)); // round to nearest int
b = int(0.5+ (b/pointCount)); // round to nearest int
ASSERT(r >=0 && r < 256);
ASSERT(g >=0 && g < 256);
ASSERT(b >=0 && b < 256);
// average
COLORREF averageRGB = RGB(int(r),int(g),int(b));
Hope this helps
Eugene Gill
Please take the time to reply and/or rate this answer if you found it useful.
Other readers will then be better informed.

February 27th, 2022, 11:33 AM
#9
Re: Store all pixel from a circle in an array?
I found a simple problem of calculating the area of a circle in pixel values. easycpstest.com/pixelcirclegenerator for example, for radius=5 pixels,the area is 97 pixels (not 78.54 pixels). Is there any place where I can find the conversion or formula that can be used to calculate the area in pixels?
Last edited by existenceproduct; February 27th, 2022 at 03:05 PM.

February 27th, 2022, 12:47 PM
#10
Re: Store all pixel from a circle in an array?
Originally Posted by existenceproduct
I found a simple problem of calculating the area of a circle in pixel values. for example, for radius=5 pixels,the area is 97 pixels (not 78.54 pixels). Is there any place where I can find the conversion or formula that can be used to calculate the area in pixels?
Don't you want to show your code producing such a problem?
Victor Nijegorodov

February 27th, 2022, 03:34 PM
#11
Re: Store all pixel from a circle in an array?
Originally Posted by existenceproduct
Is there any place where I can find the conversion or formula that can be used to calculate the area in pixels?
Are you looking for a solution to the Gauss circle problem?
https://en.wikipedia.org/wiki/Gauss_circle_problem
https://mathworld.wolfram.com/GausssCircleProblem.html
Last edited by wolle; February 27th, 2022 at 03:40 PM.

March 17th, 2022, 01:29 PM
#12
Re: Store all pixel from a circle in an array?
hello guys,
I'm trying to create lines, pixels, circles, and squares that appear onscreen by sgdk, I know there's a function, but nn I'm getting it, could anyone help me :?: moving from Florida to Alabama
Last edited by existenceproduct; May 1st, 2022 at 07:40 AM.

March 17th, 2022, 02:13 PM
#13
Re: Store all pixel from a circle in an array?
Originally Posted by existenceproduct
hello guys,
I'm trying to create lines, pixels, circles, and squares that appear onscreen by sgdk, I know there's a function, but nn I'm getting it, could anyone help me :?:
Do you mean this one?
Victor Nijegorodov

April 9th, 2022, 03:00 PM
#14
Re: Store all pixel from a circle in an array?

April 30th, 2022, 08:05 PM
#15
Re: Store all pixel from a circle in an array?
Originally Posted by wolle
thank you for the solution
Last edited by existenceproduct; May 16th, 2022 at 02:55 PM.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
