简体   繁体   English

可可触摸-如何检查UIImageView中的非矩形对象是否与另一个对象相交?

[英]Cocoa Touch - How to check if a non-rectangular object in a UIImageView intersects another object?

Say I have a UIImageView that contains an image of an object that is not rectangular, ie a round ball. 假设我有一个UIImageView,其中包含非矩形(即圆球)对象的图像。 How can I check if another UIImageView (rectangular or not) intersects, or contains a point in, that object (not its frame)? 如何检查另一个UIImageView(是否为矩形)与该对象(而不是其框架)相交或包含一个点?

Basic example: 基本示例:

I have two balls rolling around on the screen, and I want to check for collision. 屏幕上有两个滚来滚去的球,我想检查是否有碰撞。 But I don't want to check if their rects intersects eachother, since the balls are not rectangular. 但是我不想检查它们的矩形是否彼此相交,因为这些球不是矩形的。

I think if you have limited set of possible shapes then it is better to perform the check for each possible pair of object shapes rather then some generic algorithm. 我认为,如果您可能的形状集有限,那么最好对每个可能的对象形状对执行检查,而不要执行某种通用算法。 For example two circles intersect if the distance between their centers is less then the sum of their radiuses etc. 例如,如果两个圆的中心之间的距离小于其半径之和,则两个圆相交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM