获取向量中的所有点(两点之间)

时间:2012-08-02 10:16:18

标签: objective-c cocoa opengl

假设我有2分(x1,y1)和(x2,y2)。我可以从点(x1,y1)到点(x2,y2)绘制矢量。我怎样才能获得它们之间的所有可能点,例如每10个像素?

简单的可视化:
enter image description here

2 个答案:

答案 0 :(得分:2)

A点和B点之间的矢量是B-A(x2-x1,y2-y1) 如果你对该向量进行标准化,并将其乘以你想要的因子(你似乎想要10px的距离,所以你的因子是10),你可以通过将它添加到当前点(最初是原点A)直到你到达终点B.

答案 1 :(得分:1)

您可以采用较小的stepVector并逐步添加。

伪代码:

stepVector = yourVector / 10
Point1 = basePoint + stepVector
Point2 = Point1 + stepVector
...

或某事

stepVector = yourVector / 10
Point1 = basePoint + stepVector
Point2 = basePoint + (stepVector * 2)
Point3 = basePoint + (stepVector * 3)
...