CMOS
CMOS

Reputation: 2917

Objective C compare two CGPoint to see if they are close?

So I currently get the location of a touch by using

CGPoint location = [touch locationInView:self.view];

Now what I want to do is check the location on the next touch to see if the locations are close, say 25 points on x or y axis.

There are a few posts that show how to compare if two touches are equivalent but is there to calculate the distance between multiple points? Any info would be awesome.

Upvotes: 1

Views: 927

Answers (1)

Vignesh Murugesan
Vignesh Murugesan

Reputation: 747

To estimate the distance between two CGPoints, you can make use of simple Pythagorean formula:

CGFloat dX = (p2.x - p1.x);
CGFloat dY = (p2.y - p1.y);
CGFloat distance = sqrt((dX * dX) + (dY * dY));

Upvotes: 6

Related Questions