[英]How to add random points in between the given points?
如果形状是凸的,则非常简单:
def get_random_point(points):
point_selectors = np.random.randint(0, len(points), 2)
scale = np.random.rand()#value between 0 and 1
start_point = points[point_selectors[0]]
end_point = points[point_selectors[1]]
return start_point + (end_point - start_point) * scale
您指定的形状不是凸面。 但是,如果您没有额外指定哪些点构成您的形状的外部或其他约束,例如您只想允许线条平行于 x 或 y 轴,则您看到的形状在数学上没有得到充分指定。
最后备注:有一些算法可以检查一个点是否在多边形内(多边形中的点)。 然后,您可以 1) 指定边界多边形 2) 在形状的边界矩形内生成一个点,以及 3) 测试该点是否位于多边形的形状内。
插值可能值得研究:
import numpy as np
# lets suppose y = 2x and x[i], y[i] is a data point
x = [1, 5, 16, 20, 60]
y = [2, 10, 32, 40, 120]
interp_here = [7, 8, 9, 21] # the points where we are going to interpolate values.
print(np.interp(interp_here, x, y)) ## [14. 16. 18. 42.]
如果你想要随机点,那么你可以使用上面的作为指导线,然后为每个点添加/减去一些增量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.