views:

129

answers:

1

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.

+1  A: 

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.

trashgod
You are right about PathIterator, but I think I will change my representation because I want to let the user edit the curves, and it will be hard to handle with only a Path-representation.
Jonas
Why not keep both: the `Path` for rendering convenience and the derived geometry for editing? You'd have to refresh the latter when adding or removing points.
trashgod
Thanks! That's the way to go!
Jonas