We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I am new to this forum, so excuse me if I do not give enough information at once. I am trying to make a word cloud like Wordle. I am halfway through (I already have the words), but I do not know how to check if a text intersects another one, since I am also rotating the text. Any idea?
Thank you.
Answers
Well first of all one easy thing could be keeping the words all the same size. From their it will be a check and adjust process where you run it, check it, than adjust. How would you know, without checking? I can't really say, just consider how long each word is and size it depending on that.for example.
See how I added 20 on the "y" value of the second text? I was just making sure they had room. But if I wanted to make it spin, I would have to make it at least 40 or 50 in the y value, to ensure they didn't touch if they were spinning.
Hope it helped! Techwiz777
Thanks for answering! I would like to know more or less how to do it automatically. I thought on making an invisible rectangle covering the word, so the coordinates are easier to manage. Isn't there any library to check intersection? Thanks again!
You should start by reading Processing's reference about it:
http://processing.org/reference/text_.html
Other important functions:
Not useful, but for fun, Bounce Words: :D
http://studio.processingtogether.com/sp/pad/export/ro.9eHY5Fel1e0Jr/latest
It is very simple to test for the intersection between 2 rectangles provided they are not rotated (have a look at page 4 of the Geometry 2D Cookbook)
Once you rotate the them then you have a problem. You could assume that each word is inside a circle whose diameter is given by the textWidth() because it is easier to test for circle-circle intersection, but that might give unnatural separation in the text Y direction.
Alternatively you could test each side of the rotated rectangle with each side of the second rotated rectangle using simple line-line intersection.
I am not aware of any Processing V2+ compatible libraries for doing this, but someone else might.
Another way of doing collision detection is to draw whatever is drawn in main screen in a second "layer"(PGraphics). Then you check the color of desired position in this never displayed layer, to see if "that place is taken" : ). But I don't know if this can be of help here as I believe you still need to handle rotated coordinates. And check a all rect coordinates, what might be just as hard.
There is two typography libraries linked from library page, you might check if they can help you geomerative perhaps
http://processing.org/reference/libraries/#typography
Thank you very much!(including the bouncing words... quite interesting:) Geomerative is the library i was looking for. Thanks everyone!