Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrange letters of a sentence in a minimum area?

Tags:

algorithm

I'm going to write a program that rearranges letters of a sentence in a minimum area. The tool that I'm going to write this app is not important. The problem is that I nearly have no idea how I can do this.

I want something like this :

enter image description here

Is there any algorithm to sort some surfaces (let's suppose each letter a polygon surface) in a minimum area?

like image 842
s4eed Avatar asked Jun 30 '13 11:06

s4eed


3 Answers

In this paper you can find insights of Wordle, a tool to do beautiful tag clouds. It does a randomized greedy algorithm approximation of the bin packing problem.

like image 99
Scharron Avatar answered Nov 16 '22 04:11

Scharron


Its not easy at all... it is related to the "Bin Packing Problem" which is proven NP-HARD.
Additionally, your problem involves non-rectangular objects so it's a bit harder but not by magnitude.

you should go for an Optimization algorithm approach like Genetic Algorithms or such...

Google for "Bin Packing 2D" will result in quite a few helpful links and articles.

like image 40
Tomer W Avatar answered Nov 16 '22 05:11

Tomer W


My approch for such an algorithm would be a genetic one.This would be a sample data structure sample in Java.

public class Individual{
 char letter;
 double x;
 double y;
 double rotation;
}

public class Population{
 private Individual[] individuals;

 public Population(String s) {
  individuals = new Individual[s.length()];  
  for(int i = 0; i < s.length(); i++ {
   Individual individual = new Individual();
   individual.letter = s.charAt(i);
   // set random x, y, and rotation;
   individuals[i] = individual; 
  } 
 }
 // Calculate Fitness: (1/Totalspace needed ) - Overlapping Space
 // Envolve Population
}
like image 2
Lukas Eichler Avatar answered Nov 16 '22 06:11

Lukas Eichler