How to calculate the distance between two screen touches?

Hello! Please tell me how to calculate the distance between two touches of the screen fingers? This is necessary in order to scale the image, if the distance between the fingers increases , the picture increases, and Vice versa.

You should read https://docs.coronalabs.com/guide/events/touchMultitouch/.

You would need to get the event.x and event.y values for both touches and then use Pythagora’s theorem to calculate the distance.

This is some pretty straightforward math.  You have two touch points that each have an X and Y value. Let’s call them touch1 and touch2 and their values are touch1.x, touch1.y, touch2.x and touch2.y. You can then get the distance via:

local dx =  touch1.x - touch2.x local dy =  touch1.y - touch2.y local distance = math.sqrt( dx \* dx + dy \* dy )

Rob

You should read https://docs.coronalabs.com/guide/events/touchMultitouch/.

You would need to get the event.x and event.y values for both touches and then use Pythagora’s theorem to calculate the distance.

This is some pretty straightforward math.  You have two touch points that each have an X and Y value. Let’s call them touch1 and touch2 and their values are touch1.x, touch1.y, touch2.x and touch2.y. You can then get the distance via:

local dx =  touch1.x - touch2.x local dy =  touch1.y - touch2.y local distance = math.sqrt( dx \* dx + dy \* dy )

Rob