Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: algorithm help -- how to label a clock

by hawtin (Prior)
on Jun 17, 2011 at 07:54 UTC ( #910088=note: print w/ replies, xml ) Need Help??

in reply to algorithm help -- how to label a clock

Your description seems too vague to me. There are a number of different approaches.

Assuming you are not going to rotate the text then each "label" consumes a rectangle of space, and has a well defined point that it is trying to identify. A simple approach would be to position the centre of the rectangle on the location. Alternately you could define 8 cardinal points of the text rectangles (top left, top middle etc), select an appropriate one (for eleven the 'bottom centre' for example) and place that on the point you want.

The issue is that the size of the rectangles and the aesthetic effect you want will determine what works for you.

One approach I've used (in the distant past) is to place all the labels exactly where I want them (with the centre of the label in the desired location for example). Define a "goodness measure" that uses various rules (no two labels may overlap, the distance from the desired point can't be too great etc), try randomly moving one of the labels and if that increases the goodness keep it, if not try again. If you start with quite a big move size then gradually decrease it the various labels will end up in a configuration that best suits your defined measure.

This is essentially a "Simulated Annealing" approach

Comment on Re: algorithm help -- how to label a clock

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://910088]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2015-10-10 13:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (257 votes), past polls