我从start
到end
有一个区间,其中start
和end
的类型为double
。我想将间隔分为n
个点,其中两个相邻点之间的距离相同。
例如:
// Given closed interval [-3.14,3.14]:
start = -3.14
end = 3.14
n = 3
// The 3 points would be:
-3.14, 0.0, 3.14
// Where the distance between each two neighboring points is 3.14
或者:
// Given left-closed, right-open interval [0,1):
start = 0
end = 1
n = 4
// The 4 points would be:
0.0, 0.25, 0.5, 0.75
// Where the distance between each two neighboring points is .25
我对此有疑问,请多多指教
答案 0 :(得分:2)
根据您到目前为止显示的逻辑,interval
的大小为:
(end - start) / (n - 1)
(end - start) / n
(end - start) / (n + 1)
最初的左点是:
start
start + interval
。所有其他点只需在顶部添加interval