2D位置:查找向量上的哪些位置并进行计算

时间:2017-11-13 19:50:02

标签: python 2d

我有一个二维网格,每个位置都有一个浮点值:

p = [
  [0  ,0  ,0  ,0  ,0  ,0  ],
  [0  ,0  ,0  ,0  ,1.0,0  ],
  [0  ,0.5,0  ,0  ,0  ,0  ],
  [0  ,0  ,0  ,0  ,0  ,0  ],
  [0  ,0  ,0  ,0  ,0  ,0  ],
  [0  ,0  ,0  ,0  ,0  ,0  ],
]

我想知道矢量下的什么是宝座。例如,在向量(p[5][0], p[0][2])(A-> C)和向量(p[5][0], p[0][5])(A-> B)下的位置是什么:

grid without coloration

结果应该是彩色案例:

grid with coloration

所以,对于:

  • (p[5][0], p[0][2])(A-> C)=> (p[5][0], p[4][0], p[4][3], p[3][3], p[2][3], p[1][3], p[1][3], p[0][3])和最终值(0, 0, 0, 0, 0, 0.5, 0, 0)
  • (p[5][0], p[0][5])(A-> B)=> (p[5][0], p[4][1], p[3][2], p[2][3], p[1][4], p[0][5])和最终值(0, 0, 0, 0, 1.0, 0)

如何计算?

1 个答案:

答案 0 :(得分:0)

正如Willem Van Onsem所说,我正在搜索Bresenham line algorithm