programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# PathIterator

Ranch Hand
Posts: 53
• Number of slices to send:
Optional 'thank-you' note:
Hi thr,

Lets say I have a polygon object containing points p1,p2,p3,p4,p5. I want to take the line formed by any two consecutive points, say (p1,p2), (p2,p3), (p3,p4), (p4,p5) and (p5,p1). Where as using pathIterator you can traverse through polygon in one direction. Iam able to get (p1,p2), (p2,p3), (p3,p4), (p4,p5). But not (p5,p1).

How do I get the start point i.e. p1 on reaching the end point p5 so that I can take the line formed by p5,p1 line. Is there a way to get?

Ranch Hand
Posts: 381
• Number of slices to send:
Optional 'thank-you' note:
Let us know us how you are getting (p1,p2), (p2,p3), (p3,p4), (p4,p5).
There are various ways of getting the points.

Ravi Kotha
Ranch Hand
Posts: 53
• Number of slices to send:
Optional 'thank-you' note:
Using PathIterator in java.awt.geom package. Using the pathIterator iam able to traverse through the outline of polygon points.

author and iconoclast
Posts: 24207
46
• Number of slices to send:
Optional 'thank-you' note:
Perhaps you could simply store it when the iteration begins?

Wanderer
Posts: 18671
• Number of slices to send:
Optional 'thank-you' note:
Yes, when using PathIterator you need to check the return value of the currentSegment() method to determine the type of each segment, and you need to use variables to remember both the last point visited, and the starting point (or more precisley, the coordinates of the most recent SEG_MOVETO segment, which may redefine the starting point midway through the iteration). If you get to a SEG_CLOSE segment (which has no coordinates of its own), that means you need to connect the last point visited with the starting point. Typically you may have one SEG_MOVETO at the beginning, then several SEG_LINETO segments in the middle, and then one SEG_CLOSE at the end. However it's also possible to have no SEG_CLOSE at the end - but in this case, the last SEG_LINETO should include a copy of the starting point coordinates. If there's no SEG_CLOSE and if the final SEG_LINETO doesn't return to the starting point coordinates, then the path does not represent a closed figure. Sometimes that's OK, sometimes it isn't.

If this isn't making sense, then please post the code you're using, so we can better tell what you're doing, and adjust explanations appropriately.
[ January 14, 2007: Message edited by: Jim Yingst ]

 Politics is a circus designed to distract you from what is really going on. So is this tiny ad: a bit of art, as a gift, the permaculture playing cards https://gardener-gift.com