Hi Robert,

> Here's what I've come up with so far:
> 
> Arc2D thisArc = new Arc2D.Double(x, y, w, h, startAngle, 
> angleSize, Arc2D.PIE);
> 
> PathIterator pi = thisArc.getPathIterator(null);
> float[] coords = new float[6];
> while (!pi.isDone()) {
>    pi.currentSegment(coords);
>      for (int c = 0; c < 6; c++) {
>        pi.next();
>      }
> }

One problem is that the pi.next() method is for moving the iterator
to the next segment, not the next point on the segment.  You should
execute pi.next() at most once per call to pi.currentSegment().

Also, the number of coordinates in the array varies on the type of segment,
it isn't always 6 coordinates, though it is at most 6.  The PathIterator
interface documentation gives formulas for how to interpret the quad
and cubic curve segments, but it isn't the best reference to teach you
how to work with such curve segments.  If you don't already understand
how to work with 2nd and 3rd order Bezier's then the easiest thing to
do would be to use the flattening iterator which you can get from the
Shape using:

        PathIterator pi = shape.getPathIterator(null, 1.0f);

That final 1.0f parameter indicates that only lines should be returned
in the iteration and that the lines should approximate the curves well
enough that all points on the polygon they define are no more than 1.0f
units from the true curved outline.  When you do that then you will only
get SEG_MOVETO, SEG_LINETO, and SEG_CLOSE segments returned from the
iterator.

> - mapping the Arc2D to a Polygon and extracting the vertex co-
> ordinates.

There is no way to do this directly.  You would have to iterate the
Shape using the flattening call as above and then store the results
into a Polygon, but you might as well just handle the coordinates
directly.

> - throwing a GeneralPath around the Arc2D and somehow 
> extracting the co-ordinates from that.

The GeneralPath is nothing more than a general repository to store the
coordinates and segment types as used in the PathIterator format.
All this would do is move the data from one place to another.  You
would still need to use a PathIterator to get the geometry from the
GeneralPath object.

Try this template:

        PathIterator pi = arc.getPathIterator(null, 1.0f);
        float coords[] = new float[6];
        // (Technically since the flattened iteration is only allowed
        // to return move,line,close segments, we only need an array of
        // 2 floats, but I sometimes share the coords array between
        // different iterations and typically allocate 6 floats by
        // force of habit.
        float movx = 0, movy = 0, curx = 0, cury = 0;
        while (!pi.isDone()) {
            switch (pi.currentSegment(coords)) {
            case SEG_MOVETO:
                if (curx != movx || cury != movy) {
                    // If you care about all of your subpaths being
                    // closed, then pretend that there was a line
                    // segment here from (curx,cury) to (movx,movy).
                }
                curx = movx = coords[0];
                cury = movy = coords[1];
                break;
            case SEG_LINETO:
                // Handle the line segment from (curx,cury) to
                // (coords[0],coords[1]).
                curx = coords[0];
                cury = coords[1];
                break;
            case SEG_CLOSE:
                // Handle the line segment from (curx,cury) to
                // (movx,movy).
                curx = movx;
                cury = movy;
                break;
            }
            pi.next();
        }
        if (curx != movx || cury != movy) {
            // If you care about all of your subpaths being
            // closed, then pretend that there was a final line
            // segment here from (curx,cury) to (movx,movy).
        }

                                ...jim

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to