SRL Archive - Help and Support

populating an array with the points for a circle


footballjds

2012-03-02 11:18:46

Title should say it all.

I need to make a circle(I'd like to specify the diameter).

So if i looped through the array i'd go in a circle(so it'd be a tpa).

Thanks,

<3

masterBB

2012-03-02 11:21:19

A filled circle or just the outline? Also does performance matters?

footballjds

2012-03-02 11:23:26

From: masterBB
A filled circle or just the outline? Also does performance matters?


an outline, and it's so i can draw a circle with a pencil in paint…

Should i look through the math funcs? :P

weequ

2012-03-02 11:33:30

It's easy to make it so that it paint every x angle. Just use sin to calculate the y coord and cos to calculate x if I remember correctly. However that might not be the best way. (You might might some pixels or draw same pixel multiple times)

footballjds

2012-03-02 11:35:41

From: weequ
It's easy to make it so that it paint every x angle. Just use sin to calculate the y coord and cos to calculate x if I remember correctly. However that might not be the best way. (You might might some pixels or draw same pixel multiple times)


well if there isn't a function to make a circle then forget about it. This is for someone else and i cbf to utilize math i haven't used in 4 years…

masterBB

2012-03-02 11:47:40

program Circle;


function getCircleOutline(midPoint:Tpoint;radius:Integer):TPointArray;
var
x,y,width,bmp:Integer;
begin
width := radius*2+2;

DisplayDebugImgWindow(width,width);
bmp := CreateBitmap(width,width);

setLength(Result,width*width);
for x := 0 to width-1 do
for y := 0 to width-1 do
Result[x*width+y] := Point(x,y);

FilterPointsDist(Result,radius-1,radius+1,radius,radius);

DrawTPABitmap(bmp,Result,5811341);
DrawBitmapDebugImg(bmp);

end;


begin
getCircleOutline(Point(30,30),60);
end.

mormonman

2012-03-02 11:48:05

I made the circle creating function a while back, you'll just have to sort the points.

function TPAFromCircle(CX, CY, Radius: Integer): TPointArray;

footballjds

2012-03-02 12:54:52

From: mormonman
I made the circle creating function a while back, you'll just have to sort the points.

function TPAFromCircle(CX, CY, Radius: Integer): TPointArray;


by sorting the points you mean… the array jarbles the points?

mormonman

2012-03-02 14:54:14

From: footballjds
by sorting the points you mean… the array jarbles the points?


It creates the points in a circle wise function based on bresenham/midpoint algorithms. It finds one point in an 8th of the circle, then reflects it to the 7 other slices. Then it does it for the next point, etc, etc.

footballjds

2012-03-02 14:56:18

From: mormonman
It creates the points in a circle wise function based on bresenham/midpoint algorithms. It finds one point in an 8th of the circle, then reflects it to the 7 other slices. Then it does it for the next point, etc, etc.


So every 8th point in the array is correct?
Could you explain a little bit more if you don't mind? Thanks<3

I can't find the source for TPAFromCircle

EDIT: solution found, thanks, SortCircleWise(CircleTPA, 120, 120, 0, true, true);

n3ss3s

2012-03-03 03:09:30

Using "sine" and "cose" of SRL (sin and cos values loaded into arrays) is probably more efficient than anything else.

footballjds

2012-03-03 18:58:06

From: n3ss3s
Using "sine" and "cose" of SRL (sin and cos values loaded into arrays) is probably more efficient than anything else.


I didnt do a benchmark but its nearly instant as far as i see.