Skip to main content

How to create a circle using GeneralPath.

3 replies [Last post]
fordfarline
Offline
Joined: 2006-11-06

Hi everyone!

I have to create a circle or a sector using GeneralPath. This class has two methods for draw it: curveTo an quadTo. My problem is that i don´t know how to calculate the controls points. I read some about Bezier curve, but i don´t undertand it very well.

thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fordfarline
Offline
Joined: 2006-11-06

Thanks a lot!!!

I use this circle to draw in a flash file, with flagstone. I had to draw circles with start and end angle. I had probed with Arc2D class, but the flash library doesn´t understand this shape all the times. So i decided draw by myself. I have find a url, where explain how to calculate de bezier´s control points, from the url you send.

this is the url http://www.stillhq.com/ctpfaq/2002/03/c1088.html#AEN1212

It had been very useful for me. Thanks again

Jérôme Thièvre

Hi, why don't you use the Ellipse2D classes ?

Il you can't use these classes, you should take a look at this page :

http://www.whizkidtech.redprince.net/bezier/circle/

The following picture illustrates the solution to draw the quadrant AB :

A = (0,R) ; B = (R,0) ; A' = (R*kappa,R) ; B' = (R,R*kappa)
kappa = 0.5522847498

if you want to draw the circle with center (x,y) and radius R with
GeneralPath, it gives :

GeneralPath circle = new GeneralPath();

// First quadrant
circle.moveTo(x, y-R); // move to A
circle.curveTo(x+R*kappa, y-R, x+R, y-R*kappa, x+R, y); // curve to
A', B', B

// Second
circle.curveTo(x+R, y+R*kappa, x+R*kappa, y+R, x, y+R );

// Third
circle.curveTo(x-R*kappa, y+R, x-R, y+R*kappa, x-R, y);

// Last
circle.curveTo(x-R, y-R*kappa, x-R*kappa, y-R, x, y-R );

// Ensure closeness of the circle
circle.closePath;

Jérôme Thièvre

java2d@JAVADESKTOP.ORG a écrit :

>Hi everyone!
>
> I have to create a circle or a sector using GeneralPath. This class has two methods for draw it: curveTo an quadTo. My problem is that i don´t know how to calculate the controls points. I read some about Bezier curve, but i don´t undertand it very well.
>
> thanks in advance.
>[Message sent by forum member 'fordfarline' (fordfarline)]
>
>http://forums.java.net/jive/thread.jspa?messageID=170756
>
>===========================================================================
>To unsubscribe, send email to listserv@java.sun.com and include in the body
>of the message "signoff JAVA2D-INTEREST". For general help, send email to
>listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]
[moz-screenshot.jpg]

Michael Toula

float radius = 5.0f;
GeneralPath gp = new GeneralPath(new Ellipse2D.Float(x,y, radius,
radius));

This will create a circle with a radius of 5.
Mike
******************************************
Michael TOULA
Software Engineer

Dalim Software GmbH
Strassburger Str. 6
D-77694
Kehl am Rhein
GERMANY

tel: +49 7851 919 612
fax: +49 7851 735 76
web: www.dalim.com
******************************************

java2d@JAVADESKTOP.ORG
Sent by: Discussion list for Java 2D API
06/11/06 17:35
Please respond to
java2d@javadesktop.org

To
JAVA2D-INTEREST@JAVA.SUN.COM
cc

Subject
[JAVA2D] How to create a circle using GeneralPath.

Hi everyone!

I have to create a circle or a sector using GeneralPath. This class has
two methods for draw it: curveTo an quadTo. My problem is that i don´t
know how to calculate the controls points. I read some about Bezier curve,
but i don´t undertand it very well.

thanks in advance.
[Message sent by forum member 'fordfarline' (fordfarline)]

http://forums.java.net/jive/thread.jspa?messageID=170756

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the
body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]