Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: algorithm help -- how to label a clock by hawtin
in thread algorithm help -- how to label a clock by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found