C2 can detect geometric shapes drawn by Canvas?

Get help using Construct 2

» Wed Jul 08, 2015 10:52 pm

Hi everybody!

As I still don't dominate the Canvas object, I ask if is possible to C2 recognize certain shapes drawn by the player, such as an "X" and "check".

I learned to do it recognize closed shapes, but without discriminating a triangle of a circle, for example.

B
39
S
9
G
3
Posts: 261
Reputation: 4,381

» Thu Jul 09, 2015 1:18 am

@R0J0hound, do you have any suggestions for this? ^^
B
39
S
9
G
3
Posts: 261
Reputation: 4,381

» Thu Jul 09, 2015 2:24 am

Search for "gesture recognition" for a few examples that may help.

What is usually done is to compare the points of the line drawn instead of the resulting image.
One way is to evenly divide the drawn stroke and compare that with a saved stroke. The simplest way is if both strokes have the same number of points, but you can do some interpolation if the number is different.
The comparison can compare the direction or positions of the points. If by location you'll need to scale the strokes to be the same size.

For each point you add up the differences. Then that sum will indicate how similar the two shapes are. 0 would be identical and anything higher would be less similar. Typically you pick a number that would be good enough to consider it that shape.

For comparing against multiple shape you'd do the same for each and keep the one that was closest.

For comparing if a triangle was drawn then you would have to have to do something a bit more clever. Since you could have started drawing the triangle from any point and went either direction.
One idea would be to find the center of the stroke and find the distances around that to the point. Then you could compare the distances of both strokes at the same angles around the shape.

Anyway, just some ideas. I've made an example that you can find by searching that does some of the above. There are also some examples made by others as well as a plugin that could be of use.
B
97
S
36
G
131
Posts: 5,520
Reputation: 83,478

» Thu Jul 09, 2015 2:41 am

Thanks for the help, @R0J0hound.

I'm not good at math as you, and I'm more designer than programmer, so often I read tutorials and/or study through reverse engineering. ^^
B
39
S
9
G
3
Posts: 261
Reputation: 4,381