Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# How to draw a circle using 2d arrays

Moud Elma
Greenhorn
Posts: 6
Hello ,

I am trying to draw some objects using 2d arrays and animate them with AffineTransform class, I drawed the rectangle using 4 points and I had no problem but I dont know how to draw a circle using the same method, is it possible? because if I use points the circle wont be a curve. any ideas please.

here is the code

Moudy

Campbell Ritchie
Sheriff
Posts: 50749
83
Try an SSCCE to draw the circle on its own. It is actually quite easy to draw a circle, using the drawEllipse or similarly-named method of the Graphics class. Imagine a square 99×99px, then you can draw a circle inside that with whatever method I sent the link to.

Moving to our Swing forum where we usually discuss such questions.

Moud Elma
Greenhorn
Posts: 6
Thank you for the idea, I was thinking about that but the problem how can I draw a circle with the method you said and animate it with AffineTransform, because I have to use the AffineTransform (given by the Prof.) to animae the oject, is it possible to use drawoval() witth AffineTransform considering that arrays are needed with it ?.

see the code :

p and pa are 2d arrays

Campbell Ritchie
Sheriff
Posts: 50749
83
Yes, it is. What sort of transformation are you doing? What are you applying it to?

We can't do anything useful with one line.

Moud Elma
Greenhorn
Posts: 6
I used the AffineTransform and exactly the moveTo and lineTo, here is the code:

the problem is that this transform should be applied to the circle by using the moveTo and lineTo methods from the GeneralPath for the points which I defined :

like that I have an object that is simmilar to a circle but I need curves between the points and not lines.

Campbell Ritchie
Sheriff
Posts: 50749
83
I am getting really confused. The moveTo method has nothing to do with AffineTransforms.