Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: algorithm help -- how to label a clock

by hawtin (Prior)
on Jun 17, 2011 at 07:54 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found