Jonas
Jonas

Reputation: 129093

How can I draw the control points of a Bézier Path in Java?

I have created a Path of Bézier curves and it works fine to draw the path. But I don't know How I can draw the Control Points together with the Path. Is that possible or do I have to keep track of them in another datastructure?

Update: The reason to why I want to draw the control points, is that I will let the user to edit the curves using handles on the control points.

I am creating the path with:

Path2D.Double path = new Path2D.Double();
path.moveTo(0,0);
path.curveTo(5, 6, 23, 12, 45, 54);
path.curveTo(34, 23, 12, 34, 2, 3);

And drawing it with:

g2.draw(path);

I have tested with PathIterator as trashgod suggested, but it will be hard to manage the curves that way if I want the user to be able to edit the control points.

Upvotes: 3

Views: 1857

Answers (1)

trashgod
trashgod

Reputation: 205885

You can obtain a PathIterator to reference the array of coordinates for each point in the Shape. You can use these to draw resize handles and control points along the curve when editing. Here's an example of editing using a custom curve implementation.

Upvotes: 2

Related Questions