[英]How can I calculate a point between two given points in processing?
I have two given coordinates, for example (20,30) and (90,40). 我有两个给定的坐标,例如(20,30)和(90,40)。 How can I find out a point on the line between these two points?
如何在这两点之间的线上找到一个点?
I need to do this in processing but also a general mathematical solution would help me. 我需要在处理过程中执行此操作,但是一般的数学解决方案也会对我有所帮助。
To find the midpoint, just use the midpoint formula: 要找到中点,只需使用中点公式:
float midX = (pOne.x + pTwo.x)/2;
float midY = (pOne.y + pTwo.y)/2;
To find another point on the line, you could use Processing's built-in lerp()
function. 要找到线上的另一点,可以使用Processing的内置
lerp()
函数。
float midX = lerp(pOne.x, pTwo.x, .5);
float midY = lerp(pOne.y, pTwo.y, .5);
More info can be found in the reference . 在参考资料中可以找到更多信息。
You can interpolate with 您可以插值
x = (0, 1); // anything between 0 and 1
c = x * a + (1 - x) * b;
where a
, b
and c
are points. 其中
a
, b
和c
是点。
Java doesnt have lerp so here it is how it works in general Java没有lerp,所以这里是它的一般工作方式
float lerp(float point1, float point2, float dist) {
return point1 + dist * (point2 - point1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.