如何画石原-转换(圈中圈没有交集)? [英] How to draw ishihara-transformations (circles in circle without intersection)?

查看:238
本文介绍了如何画石原-转换(圈中圈没有交集)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我需要绘制的图片,如下的C#/ VB.NET


请注意,我的问题是不是在C#画圆。

Question: I need to draw pictures as below in C#/VB.NET
Note that my problem is NOT drawing circles in C#.

我的问题是他们画没有太多的空白,没有交集。


我的想法将使用轨道,然后绘制中心圈的轨道线。 (与一些轨道线做大一些仅用于小圆圈)
中的问题是,不应该有交叉点

My problems is drawing them without much whitespace and without intersection.
My thought would be using "Orbits" and then draw the circles with center on the "orbit" lines. (with some orbit lines for bigger and some only for smaller circles) The problem is that there should be no intersections.

任何人有一个更好的主意吗?
或我怎么会测试给定半径的要绘制圆是否会与已经存在的圈子?

Anyone has a better idea ? Or how would I test whether a to be drawn circle of given radius would intersect with an already present circle ?

推荐答案

圈的交集是容易计算:如果沿X的差异加上沿y的差的平方的平方小于半径之和的平方,圆圈相交

Intersection of circles is easy to calculate: if the square of the difference along the x plus the square of the difference along the y is less than the square of the sum of the radii, the circles intersect.

请注意,这是已经优化过了一点,因为它避免采取平方根。额外的优化是可能的,例如当沿x差值大于半径的总和,他们将永远不会相交。

Note that this is already optimized a bit, as it avoids taking a square root. Additional optimizations are possible, e.g. when the difference along the x is greater than the sum of the radii, they will never intersect.

只是测试对所有现有圈子的新圈子,就大功告成了

Just test the new circle against all existing circles, and you're done.

这是O(n ^ 2),但很容易和非常快的,因为每个测试只是少数,快速的操作。

This is O(n^2), but is easy and pretty fast as each test is just a few, fast operations.

当然,你可以寻找你不必对测试所有其他每个圆圈的优化,但这些都是昂贵的,大量的代码,因此只值得的很多圈。 。第一次尝试了简单的解决方案。

Of course, you could look for an optimization that you do not have to test each circle against all others, but those are expensive, lots of code, and thus only worth it for lots of circles. Try out the simple solution first.

在C ++代码(对不起,我不说话VB):

In C++ code (sorry, I don't speak VB):

struct { double x, y, r; } Circle;

bool circleIsAllowed(const std::vector<Circle>& circles, const Circle& newCircle)
{
   for(std::vector<Circle>::const_iterator it = circles.begin(); it != circles.end(); ++it) // foreach(Circle it in circles)
   {
      double sumR = it->r + newCircle.r; // + minimumDistanceBetweenCircles (if you want)
      double dx = it->x - newCircle.x;
      double dy = it->y - newCircle.y;
      double squaredDist = dx*dx + dy*dy;
      if (squaredDist < sumR*sumR) return false;
   }

   return true; // no existing circle overlaps
}



编辑:纠正小错误,并注意到问题是不是C ++

corrected minor bugs, and noticed that the question wasn't about C++

这篇关于如何画石原-转换(圈中圈没有交集)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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