简体   繁体   English

多少线经过障碍物

[英]How much of line goes through obstacle

I got a problem to solve. 我有一个要解决的问题。 Look at the picture: Image . 看图片: 图片

  • Red filled Ellipse is an obstacle. 红色填充的椭圆形是一个障碍。
  • Black dots are beginning and end of "road". 黑点是“道路”的起点和终点。
  • Blue line, is shortest way from one point to another. 蓝线是从一个点到另一个点的最短方法。

I draw obstacles using mouse (mouse click creates ellipse), then i put in cords of start and the end, and then i use DrawLine to draw line from point to point. 我使用鼠标绘制障碍物(鼠标单击会创建椭圆形),然后放入起点和终点的绳索,然后使用DrawLine从点到点绘制线。 The question here is, how can i check or count, how many pixels of line, goes trough obstacle? 这里的问题是,我如何检查或计数,行数像素,越过障碍?

I thought of putting every pixel color in a 2D array before drawing the line, and then check it somehow on the numbers, counting shortest way from point to point, and checking how many 255's (obstacle number) would it meet in that array? 我想过在画线之前将每种像素颜色放入2D阵列中,然后以某种方式在数字上进行检查,计算点到点的最短距离,并检查在该阵列中会遇到多少个255(障碍物数)? As you see, i can create obstacle that way, so line will go trough the middle, just some part of it, or even next to it. 如您所见,我可以通过这种方式创建障碍,因此线会穿过中间,仅一部分或什至旁边。 I am simply lacking any idea how to do that. 我根本不知道该怎么做。 I need it, so i could rate every "road". 我需要它,所以我可以为每条“道路”评分。 More it goes trough obstacle, the less rate it gets. 通过障碍越多,获得的速率就越少。

Any ideas? 有任何想法吗? Any algorithm? 有什么算法吗?

  1. Using the equations of the ellipse and the line , find the intersection points of the line with the outline of the ellipse (there may be 2, 1 or no intersections). 使用椭圆直线的方程,找到直线与椭圆轮廓的交点(可能有2个,1个或没有交点)。 You can find a worked example of this here . 您可以在这里找到一个可行的示例。
  2. If there are indeed 2 intersection points, use the distance formula to calculate the distance between them. 如果确实有2个相交点,则使用距离公式计算它们之间的距离。

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

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