The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Center of Attention

Posted by Matt Gerrans on December 26, 2001 at 6:18 PM

> I have many shape objects. I need to find the centre of the shape object.
> ...
> Is there any mathematical formula to do it. [?]

Yes, there is a mathematical formula, but it kind of requires that the shape also be described by a mathematical formula.

If you have arbitrary shapes, then one simple trick is to just calculate the average position (x & y) of all the pixels inside the bounds of a particular shape. That would give you the weighted center. For this, the base shape object should have a contains(x,y) type method that allows you to test whether a given pixel is in the shape's region or not.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us