Skip to content

Commit

Permalink
fix: image in docs and technical description
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxaneBurri committed Apr 17, 2023
1 parent 83f4883 commit beaa682
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This repository creates a word cloud from a list of words.

![Screenshot from 2023-03-24 15-27-02](https://user-images.githubusercontent.com/43374563/227554160-f9c18a2c-d2df-43e7-a9d3-49801a9b94a3.png)
![Screenshot from 2023-03-24 15-27-02](docs/word_cloud.png)

# Documentation

Expand Down
Binary file added docs/circleintervals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/circleparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/collision.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/moveword.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/word_cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 19 additions & 18 deletions technical_descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

A word cloud

![word_cloud](https://user-images.githubusercontent.com/43374563/230405197-985de0df-5e9b-4c76-9f38-04ba9bb5d6f0.png)
![word_cloud](docs/word_cloud.png)

## Implementation

### Set up
- Set the coordinate of the container
- Sort the words by confidence level. The biggest in first.
- Sort the words by descending confidence level (biggest in first).
- Define each word as a rectangle with the centre coordinate, width and height.
- The size of the rectangle corresponds to the confidence level. The larger the confidence, the larger the rectangle
- The size of the rectangle is proportional to the confidence level. The larger the confidence, the larger the rectangle
- The front size is define as: $(a - b) (\frac{1}{1 - b})^{2}(max - min) + min$, where $a$ is the confidence level and $b$ the cut off.

There are many words with a high confidence level and few with a low confidence level. The aim is to be able to differentiate words with high confidence levels and less differentiate words with lower confidence levels.
Expand All @@ -26,12 +26,12 @@ A word cloud
### Place the other words in a random position on the container
- Define a circle with centre the centre of the container

![container](https://user-images.githubusercontent.com/43374563/230428879-d447779d-c99a-4970-a109-255be626a1a2.png)
![container](docs/circleparent.png)

- If there is already some words placed in the word cloud, the centre of the circle is the mass sum of already placed words.
- If there is already some words placed in the word cloud, the centre of the circle is the center of mass of already placed words.
- We cut the circle in multiple intervals, each of these intervals corresponds to degrees

![intervals](https://user-images.githubusercontent.com/43374563/230429897-7b9ae668-224d-417b-8cac-7c1986777931.png)
![intervals](docs/circleintervals.png)

- We create a weight for each interval in the circle

Expand All @@ -41,21 +41,22 @@ Because the word will then be moved to the words already placed. This circle the
We then have a weight vector that counts the number of words placed in a certain interval
$w = [1, 4, 0, 3]$

So that the intervals with the fewest words have the best chance of being drawn, we subtract the maximum height from all the weights $w_{i} = [3, 0, 4, 1]$
So that the intervals with the fewest words have the best chance of being drawn, we subtract the maximum weight from all the weights $w_{i} = [3, 0, 4, 1]$

The cumulative sum is then calculated $w_{c} = [3, 3, 7, 8]$

A number is drawn at random between 0 and the maximum of the cumulative sum (from 0 to 3 it corresponds to $[0°, 90°[$

So intervals with fewer words will have a better chance of being chosen.
So intervals with fewer words will have a higher chance of being chosen.

### Move words
Now that we have placed our words on the circle, we will move it closer to the already placed words.

- We compute the move direction, by summing the differences between the already placed words and the current word.
![moveWord](https://user-images.githubusercontent.com/43374563/232424322-d95c26d3-d313-42a9-aa91-a3920228b54e.png)

We move the $(x_{1}, y_{1})$ point in the direction of the $(x_{2}, y_{2})$ of a step $step$ in the hypontenus and the new position of the word is in $(x_{3}, y_{3})$
![moveWord](docs/moveword.drawio.png)

We move the $(x_{1}, y_{1})$ point in the direction of the $(x_{2}, y_{2})$ of a step $step$ in the hypothenus and the new position of the word is in $(x_{3}, y_{3})$
- $dx = \frac{step}{h}x_{2}$
- $dy = \frac{step}{h}y_{2}$
- $x_{3} = x_{1} + dx$
Expand All @@ -65,19 +66,19 @@ We move the $(x_{1}, y_{1})$ point in the direction of the $(x_{2}, y_{2})$ of a
We move with the previous calculation of our word, but care must be taken to avoid collisions with other words.
We calculate whether the move creates a collision on x and y:

![collision](https://user-images.githubusercontent.com/43374563/232430419-666b03f3-3abe-492f-89d8-097a596b8ee6.png)

### Collisions
To calculate collisions, we check if the distance between the centre of the current word and the centre of already placed words are not smaller than the height and width of each word:
- $A_{x} - B_{x} > \frac{A_{w_{1}}}{2} + \frac{B_{w_{2}}}{2}$
- $A_{y} - B_{y} > \frac{A_{h_{1}}}{2} + \frac{B_{h_{2}}}{2}$

![collision](https://user-images.githubusercontent.com/43374563/232430419-666b03f3-3abe-492f-89d8-097a596b8ee6.png)


- If not, we move the current word and start again
- If collision on x, we move the y position of the current word and start again
- If collision on y, we move the x position of the current word and start again
- If collision on both sides, the word is placed and we are done!
- If not, we move the current word and start again
- If collision on x, we move the y position of the current word and start again
- If collision on y, we move the x position of the current word and start again
- If collision on both sides, the word is placed and we are done!

### Collisions
To calculate collisions, we check if the distance between the centre of the current word and the centre of already placed words are not smaller than the height and width of each word:

### Boundary box
When we have placed all the words, we calculate the boundary box of our word cloud. Thanks to this box, we can move all the words in our word cloud at once.
Expand Down

0 comments on commit beaa682

Please sign in to comment.