簡體   English   中英

如何在處理中計算兩個給定點之間的點?

[英]How can I calculate a point between two given points in processing?

我有兩個給定的坐標,例如(20,30)和(90,40)。 如何在這兩點之間的線上找到一個點?

我需要在處理過程中執行此操作,但是一般的數學解決方案也會對我有所幫助。

要找到中點,只需使用中點公式:

float midX = (pOne.x + pTwo.x)/2;
float midY = (pOne.y + pTwo.y)/2;

要找到線上的另一點,可以使用Processing的內置lerp()函數。

float midX = lerp(pOne.x, pTwo.x, .5);
float midY = lerp(pOne.y, pTwo.y, .5);

參考資料中可以找到更多信息。

您可以插值

x = (0, 1); // anything between 0 and 1
c = x * a + (1 - x) * b;

其中abc是點。

Java沒有lerp,所以這里是它的一般工作方式

float lerp(float point1, float point2, float dist) {
    return point1 + dist * (point2 - point1);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM