views:

125

answers:

1

When we touch with two fingers in a UIScrollView, we get two CG points. I want to find the distane between them. Then like I do the pinch(inside or outside). Then we will again get two points. Then after finding the distance again between these two points , I want to decide whether I pinched in or out. If i have pinced in, surely the new distance will be lesser and viceversa.

But dont know how to find an accurate measurement for the distance between 2 points, so that i can compare? Anyone have an idea how to do this?

+6  A: 

Distance between p1 and p2:

CGFloat xDist = (p2.x - p1.x);
CGFloat yDist = (p2.y - p1.y);
CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist));

Background: Pythagorean theorem

Edit: if you only need to calculate if the distance between the points increases or decreases, you can omit the sqrt() which will make it a little faster.

Ole Begemann
That's pretty neat. Go math.
Danilo Campos