Safe Mode
Safe Mode

Reputation: 140

Drawing a curve in java Graphics2D

How can I draw a curve using java graphics2D?

Upvotes: 0

Views: 12266

Answers (2)

Soley
Soley

Reputation: 1766

If you just want to draw curves, then use either Path2D class (Path2D.Float or Path2D.Double) which provide the methods .moveTo(x, y), .lineTo(x, y), .curveTo(cp1x, cp1y, cp2x, cp2y, endx, endy), and .quadTo(cpx, cpy, endx, endy).

If you want to really dig into how curves work, then check this wonderful tutorial http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/

Upvotes: 4

TMBT
TMBT

Reputation: 1183

If you're referring to a curve like around a circle, use the drawArc() method found in the Graphics class. Here's the API page for it: http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#drawArc%28int,%20int,%20int,%20int,%20int,%20int%29.

For cubic and quadratic curves, use the java.awt.geom package. Here's the Oracle page telling you how to use it: http://docs.oracle.com/javase/tutorial/2d/geometry/primitives.html.

Upvotes: 0

Related Questions