This all depends on your definition of "expand shape". The code snippet
below expands the shape by "d" distance perpendicular to every point on
the outline of the shape without regard to the center of the shape. In
other words, the resulting shape includes all points that were within
the original shape and also all other points that were within d distance
from the interior of the original shape.
I am not familiar enough with what you are trying to accomplish in order
to suggest a solution. Are you simply trying to scale the shape outward
from its geometrical center? I'm not sure what you mean by "geometrical
center", though - is that an average of all of the points on the
outline? Or is it an average of all of the interior points? Or an
average of the bounds? Or is it something else?
...jim
Yinhe Cao wrote:
I have checked the interface Area, and there is no method to compute the
geometrical center of the area such as:
Point2D center()
The point is if the area interface is extended to incluse the center
method, expandShape method should be very simple and direct to implement
by using AffineTransform.
Yinhe Cao
Jim Graham wrote On 07/17/06 14:39
You can use the Area class to add in the original Shape:
public Shape expandShape(Shape s, float d) {
BasicStroke bs = new BasicStroke(d);
// or new BasicStroke(d, CAP_ROUND, JOIN_ROUND);
Area a = new Area(bs.createStrokedShape(s));
a.add(new Area(s);
return a;
}
Note that the JOIN setting by default is MITER which may not match your
expectations for what it means to "expand the boundary of a Shape".
ROUND would result in a smoother resulting outline...
...jim
Chris Nokleberg wrote:
I'd like to expand the boundary of an arbitrary Shape. If I use a
BasicStroke createTransformedShape, the result is perfect except for
the resulting hole. I currently get rid of the hole by iterating over
the path, splitting the shape into multiple subshapes, and then
comparing the bounds of each subshape to find the outermost one. This
is bunch of work just to undo the unnecessary work BasicStroke has
already done, though. Any suggestions on a cleaner solution?
Thanks,
Chris
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff JAVA2D-INTEREST". For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST". For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".