检测CGPoint是否在多边形内 [英] Detect if CGPoint within polygon
问题描述
我有一组CGPoints组成多边形形状,如何检测单个CGPoint是多边形内部还是外部?
I have a set of CGPoints which make up a polygon shape, how can I detect if a single CGPoint is inside or outside of the polygon?
说,
我可以使用 CGRectContainsPoint $
I can use CGRectContainsPoint
when the shape is a regular 4-sided shape but I can't see how I would do it with an odd shape.
推荐答案
您可以创建一个 CG(Mutable)PathRef
(或 UIBezierPath
$ c> CGPathRef ),并使用 CGPathContainsPoint
函数来检查点是否在该路径内。如果使用 UIBezierPath
,也可以使用 containsPoint:
方法。
You can create a CG(Mutable)PathRef
(or a UIBezierPath
that wraps a CGPathRef
) from your points and use the CGPathContainsPoint
function to check if a point is inside that path. If you use UIBezierPath
, you could also use the containsPoint:
method.
这篇关于检测CGPoint是否在多边形内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!