# Spiral touch recognazation

Attention Topic was automatically imported from the old Question2Answer platform.

Hi,
I’m trying to recognize a form like in the image. it’s like spiral. Not need to be exactly this form, a six will be valid for example. the form can be done from the center to outside or outside to center.

I stored all points in array, so i can know what is the path that user have done.

Any help? Have a nice day.

You could calculate the vector between each successive point and check the difference of angle between them. If the sum of all the angles reaches `TAU` (or `2*PI`), the path can be considered circling once.

Something like this (disclaimer: pseudocode, not tested)

``````var vectors = []
for i in range(1, len(points)):
var previous = points[i - 1]
var current = points[i]
vectors.append(current - previous)

var total_angle = 0.0
for i in range(1, len(vectors)):
var previous = vectors[i - 1]
var current = vectors[i]
total_angle += previous.angle_to(current)

if total_angle >= TAU:
print("You circled once counter-clockwise")
elif total_angle <= -TAU:
print("You circled once clockwise")
``````

Note that this algorithm does not account for any going-backs (if you care, check changes of sign of the angles) and doesn’t use a center.