0

I wish to create a dynamic outline to a Shape (AWT) by adding objects (with draw functions) to appropriate positions on screen along the shape's perimeter. I want a roughly even distance between each object. (An alternative approach to the same affect will be fine.)

How might I acquire the locations for these objects? I know shapes have a path iterator, but I have no idea how to use it.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Perry Monschau
  • 883
  • 8
  • 22

2 Answers2

2

You might look at a library such as the one described in A Shape Diagram Editor.

If you want to experiment, GraphPanel is a simple object drawing program that features moveable, resizable, colored nodes connected by edges. If the nodes were a little smaller, they'd be moveable points on a Shape that can be iterated as shown here for Polygon.

Addendum: I want a roughly even distance between each object.

The class Node exposes a number of static methods that operate on a List<Node> such as selected. Existing implementations serve, for example, to translate or resize multiple selections as a unit. Functions for Align and Distribute could be implemented similarly. I'd look at LayoutManger as an example for the latter.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    @AndrewThompson: Good point; I overlooked that aspect of the question. More above. – trashgod May 21 '12 at 01:44
  • I don't see how this helps. The problem in question is finding an evenly distributed number of points along a shape's perimeter. Perhaps I wasn't very clear on that. – Perry Monschau May 21 '12 at 10:34
  • It would depend on the `Shape`; here's an [example](http://stackoverflow.com/a/2510048/230513) that relies on the parametric equation of a circle. It could be generalized using the parametric equation for an ellipse. – trashgod May 21 '12 at 14:17
  • So there's no simple way to just get equally distributed points on any shape? – Perry Monschau May 22 '12 at 13:45
  • I don't see such a method in the [`Shape`](http://docs.oracle.com/javase/6/docs/api/java/awt/Shape.html) interface, but you can create your own sub-interface and delegate to existing implementations that you intend to support. – trashgod May 22 '12 at 14:22
2

Use FlatteningPathIterator to get points for Shape's path.

Also you can use BasicStroke's method

public Shape createStrokedShape(Shape s)

to get Shape's outline with desire width.

StanislavL
  • 56,971
  • 9
  • 68
  • 98