如何找到两个CG点之间的距离?

编程入门 行业动态 更新时间:2024-10-24 20:20:26
本文介绍了如何找到两个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点之间的距离?

本文发布于:2023-07-27 23:14:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:距离   两个   CG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!