Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the distance between two CG points?

When we do multitouch with two fingers in a UIScrollView, we get two CG points. I want to find the distance between them. Then when again we 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 pinched in, surely the new distance will be lesser and vice versa.

But don't know how to find an accurate measurement for the distance between 2 points for doing comparison ? Is anyone having idea about this ?

like image 910
wolverine Avatar asked Dec 15 '09 10:12

wolverine


People also ask

How do you find the distance between two intercepts?

First, subtract y2 - y1 to find the vertical distance. Then, subtract x2 - x1 to find the horizontal distance. Don't worry if the subtraction yields negative numbers. The next step is to square these values, and squaring always results in a positive number.


1 Answers

You can use the hypot() or hypotf() function to calculate the hypotenuse. Given two points p1 and p2:

CGFloat distance = hypotf(p1.x - p2.x, p1.y - p2.y); 

And that's it.

like image 124
lucius Avatar answered Oct 07 '22 17:10

lucius