简体   繁体   English

Select 阵列上未对齐的 2 个坐标之间的像素

[英]Select pixels between 2 coordinates on an array that are not aligned

It is quite easy to select the pixels in an array that are on the same row or column. select 阵列中位于同一行或同一列的像素非常容易。 But how does one for example select pixels in a semi-straight line between [10,10] and [17,32] in a 40x40 array?但是,例如 select 像素如何在 40x40 阵列中的 [10,10] 和 [17,32] 之间的半直线中?

Unfortunately, the case you gave, does not have any integral points on the line segment joining (10,10) and (17,32).不幸的是,您给出的案例在连接 (10,10) 和 (17,32) 的线段上没有任何积分点。 Let's say we have to generate a random point on the line segment joining A (10,10) and B (80,130).假设我们必须在连接 A (10,10) 和 B (80,130) 的线段上生成一个随机点。

This is more of a mathematics problem than programming.这更像是一个数学问题而不是编程问题。

The points on the semi-straight line joining A and B, satisfies this relation:连接 A 和 B 的半直线上的点满足以下关系:

12x - 7y = 50

This is a Linear Diophantine Equation, its roots satisfy this general expression这是一个线性丢番图方程,它的根满足这个一般表达式

x = 10 + 7t
y = 10 + 12t

Now, generate a random integer t, and substitute that value in the above general expression, to get a random point on this straight line.现在,生成一个随机的 integer t,并将该值代入上述一般表达式中,得到这条直线上的一个随机点。

In order for the random point to be between the given two points, t should be such that (0 <= t <= 10) ( Equality holds for the given two points, ie A and B )为了使随机点位于给定的两点之间,t 应满足 (0 <= t <= 10) (对于给定的两点,即 A 和 B 等式成立

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

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