4

I'm trying to split a generic Shape into list of Points so we can move a certain sprite along the path depending on a certain percentage.

Right now I can split the shape into multiple points:

Point distribution

This was produced by the following code:

shapeComp = system.gui.getParentWindow(event).getComponentForPath('Root Container.Path')
shape=shapeComp.getShape()
pathIterator = FlatteningPathIterator(shape.getPathIterator(AffineTransform()), 1)
graphics = system.gui.getParentWindow(event).graphics

segment = jarray.zeros(6,'d')
path = []

while not pathIterator.isDone():
    pathIterator.currentSegment(segment)
    path.append([segment[0], segment[1]])
    graphics.fillOval(int(segment[0]), int(segment[1]), 5, 5)
    pathIterator.next()

As you can see on the picture, the points are not evenly distributed along the path. Is there a way to make the distance between all points the same?

Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
Thijs
  • 41
  • 3

1 Answers1

0

As you can find in the javadoc there is a additional attribute for flattness. So you should be able to just set the second argument to some specific value an get what you expect. However if this is true for all cases I don't know.

flatness - the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve

Christian
  • 1,664
  • 1
  • 23
  • 43
  • It is true that there is a Maximum distance, but what I need is an exact distance between 2 points. So I would get segments of the same length. Any idea on how this would be possible? – Thijs Dec 11 '17 at 11:40
  • Ohh I see, sorry this isn't possible with the default implementation. For this you have to implement the PathIterator Interface by yourself. – Christian Dec 11 '17 at 12:34