如何找到两个CG点之间的距离? [英] How to find the distance between two CG points?

查看:135
本文介绍了如何找到两个CG点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在UIScrollView中用两个手指做多点触摸时,我们得到两个CG点。我想找到他们之间的距离。然后再次我们做捏(内部或外部),然后我们将再次得到两点。然后,在找到这两个点之间的距离后,我想决定我是否捏住了。如果我已经挤进,肯定新的距离会更小,反之亦然。

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.

但不知道如何找到2点之间的距离的精确测量做比较?

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 ?

推荐答案

p1 code> p2 :

Distance between p1 and p2:

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

背景:勾股定​​理

编辑:如果您只需要计算点之间的距离是增加还是减少, sqrt(),这将使它更快一点。

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.

这篇关于如何找到两个CG点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆