在ios中绘制三角形上的小圆圈图像

时间:2015-08-30 15:55:28

标签: ios image drawing geometry

我有一个三角形,我将在其上放置空心圆来创建一个花环(我们可以称之为念珠)。 每个圆圈都是我需要在特定位置放置三角形的图像。

伙计们,请告诉我如何才能实现?如果您需要更加明确,请告诉我。

提前致谢!

2 个答案:

答案 0 :(得分:0)

像这样:

目标-C:

UIBezierPath* polygonPath = UIBezierPath.bezierPath;
[polygonPath moveToPoint: CGPointMake(80.5, 33)];
[polygonPath addLineToPoint: CGPointMake(119.9, 101.25)];
[polygonPath addLineToPoint: CGPointMake(41.1, 101.25)];
[polygonPath closePath];
[UIColor.grayColor setFill];
[polygonPath fill];

UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(58, 56, 45, 45)];
[UIColor.redColor setFill];
[ovalPath fill];
斯威夫特:

var polygonPath = UIBezierPath()
polygonPath.moveToPoint(CGPointMake(80.5, 33))
polygonPath.addLineToPoint(CGPointMake(119.9, 101.25))
polygonPath.addLineToPoint(CGPointMake(41.1, 101.25))
polygonPath.closePath()
UIColor.grayColor().setFill()
polygonPath.fill()

var ovalPath = UIBezierPath(ovalInRect: CGRectMake(58, 56, 45, 45))
UIColor.redColor().setFill()
ovalPath.fill()

两者都产生了这个:

enter image description here

或者这个:

目标-C:

UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(40, 18, 91, 91)];
[UIColor.redColor setFill];
[ovalPath fill];

UIBezierPath* polygonPath = UIBezierPath.bezierPath;
[polygonPath moveToPoint: CGPointMake(85.5, 18)];
[polygonPath addLineToPoint: CGPointMake(124.9, 86.25)];
[polygonPath addLineToPoint: CGPointMake(46.1, 86.25)];
[polygonPath closePath];
[UIColor.grayColor setFill];
[polygonPath fill];

夫特:

var ovalPath = UIBezierPath(ovalInRect: CGRectMake(40, 18, 91, 91))
UIColor.redColor().setFill()
ovalPath.fill()

var polygonPath = UIBezierPath()
polygonPath.moveToPoint(CGPointMake(85.5, 18))
polygonPath.addLineToPoint(CGPointMake(124.9, 86.25))
polygonPath.addLineToPoint(CGPointMake(46.1, 86.25))
polygonPath.closePath()
UIColor.grayColor().setFill()
polygonPath.fill()

为此:

enter image description here

用框架:

目标-C:

CGContextRef context = UIGraphicsGetCurrentContext();

CGRect frame = CGRectMake(75, 28, 76, 66);
CGContextSaveGState(context);
CGContextBeginTransparencyLayer(context, NULL);
CGContextClipToRect(context, frame);

UIBezierPath* polygonPath = UIBezierPath.bezierPath;
[polygonPath moveToPoint: CGPointMake(CGRectGetMinX(frame) + 1.48684 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 0.42424 * CGRectGetHeight(frame))];
[polygonPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 1.98823 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 1.42424 * CGRectGetHeight(frame))];
[polygonPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.98546 * CGRectGetWidth(frame), CGRectGetMinY(frame) + 1.42424 * CGRectGetHeight(frame))];
[polygonPath closePath];
[UIColor.grayColor setFill];
[polygonPath fill];

UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(CGRectGetMinX(frame) + floor((CGRectGetWidth(frame) - 44) * 0.50000 + 0.5), CGRectGetMinY(frame) + floor((CGRectGetHeight(frame) - 44) * 1.00000 + 0.5), 44, 44)];
[UIColor.redColor setFill];
[ovalPath fill];

CGContextEndTransparencyLayer(context);
CGContextRestoreGState(context);

夫特:

let context = UIGraphicsGetCurrentContext()

let frame = CGRectMake(75, 28, 76, 66)

CGContextSaveGState(context)
CGContextBeginTransparencyLayer(context, nil)

CGContextClipToRect(context, frame)

var polygonPath = UIBezierPath()
polygonPath.moveToPoint(CGPointMake(frame.minX + 1.48684 * frame.width, frame.minY + 0.42424 * frame.height))
polygonPath.addLineToPoint(CGPointMake(frame.minX + 1.98823 * frame.width, frame.minY + 1.42424 * frame.height))
polygonPath.addLineToPoint(CGPointMake(frame.minX + 0.98546 * frame.width, frame.minY + 1.42424 * frame.height))
polygonPath.closePath()
UIColor.grayColor().setFill()
polygonPath.fill()

var ovalPath = UIBezierPath(ovalInRect: CGRectMake(frame.minX + floor((frame.width - 44) * 0.50000 + 0.5), frame.minY + floor((frame.height - 44) * 1.00000 + 0.5), 44, 44))
UIColor.redColor().setFill()
ovalPath.fill()


CGContextEndTransparencyLayer(context)
CGContextRestoreGState(context)

这显然不会在三角形中画出一堆小圆圈,但是你没有指明需要绘制多少个圆圈,因此如果没有这些非常重要的信息,你将无法进一步帮助你,但这将是给你一个开始。

作为参考,这里是您需要访问的地方,以下信息涉及包装问题和数学,特别是包装三角形内部的环绕问题:

https://en.wikipedia.org/wiki/Malfatti_circles

http://hydra.nat.uni-magdeburg.de/packing/crt/crt.html#Download

https://en.wikipedia.org/wiki/Circle_packing_in_an_equilateral_triangle

然后这个:

  

等边三角形等密盘的密集填充R. L. Graham,   B. D. Lubachevsky

     

以前公布的等边圆盘包装   三角形最多处理了21个磁盘。我们使用新的离散事件   模拟算法,可生成多达34个磁盘的包装。对于每一个   n在22≤n≤34的范围内,我们提出了我们认为最密集的东西   可能在等边三角形中包装n个相等的圆盘。对于   这些我们还列出了第二个,通常是第三个,有时是第二个   我们发现的第四个最好的包装。在每种情况下,   包装结构意味着最小距离d(n)   磁盘中心之间是具有整数的多项式Pn的根   系数。在大多数情况下,我们没有明确地计算Pn,而是全部   我们计算并报告d(n)到15位有效十进制数字的情况。

     

等边三角形中的磁盘填充与正方形或三角形中的磁盘填充不同   对于三角形而言,圆圈中存在无限多个值   n的精确值是已知的n,其中n是已知的   形式Δ(k):= k(k + 1)2。还推测d(n-1)= d(n)   在这种情况下。根据我们的计算,我们提出了猜想   七个其他无限类n的最佳填充,即

n=Δ(2k)+1,Δ(2k+1)+1,Δ(k+2)−2,Δ(2k+3)−3,Δ(3k+1)+2,4Δ(k), and 2Δ(k+1)+2Δ(k)−1.
     

我们还报告了我们找到的其他n值的最佳包装   这些形式大于34,即n = 37,40,42,43,46,   49,56,57,60,63,67,71,79,84,92,93,106,112,121和254,   还有n = 58,95,108,175,255,256,258和260.我们这样说   n个磁盘的无限类包装,n = n(1),n(2),... n(k),...,是   紧,如果[1 / d(n(k)+1)-1 / d(n(k))]与k一起偏离零   到无穷远。我们猜想我们的一些无限类是   紧,别人不紧,而且有无数紧   类。

http://www.combinatorics.org/ojs/index.php/eljc/article/view/v2i1a1

这也是:

  

摘要

     

本文提出了一种计算方法,可以找到好的,推测的   等边三角形的最佳覆盖,最多36个相等   界。该算法由两个嵌套级别组成:内部   三角形的未覆盖区域由当地最小化   优化例程,同时圆的半径保持不变。   半径适应外层以找到局部最优   覆盖。通过应用算法获得良好的覆盖   反复随机初始配置。

     

确定覆盖物的结构和坐标   使用数学方法高精度地计算每个圆   由拉杆组成的理想物理结构模型   和无摩擦销接头。找到的最佳等边覆盖物   显示最多36个圆圈的三角形,其中19个是其中之一   新的或改进早期出版的封面。

http://projecteuclid.org/euclid.em/1045952348

然后最后,这个:

https://en.wikipedia.org/wiki/Malfatti_circles

答案 1 :(得分:0)

感谢Larcerax。

我需要在三角形的边界上绘制53个圆圈,就像念珠一样。每个圆圈将在特定距离绘制。 在53个圆圈中,5个比其他圆圈大(角落(顶点)3个,2个中间2个)。 三角形会像Cone一样。