![](/img/trans.png)
[英]In python random walker ,how can I set a random starting point instead of setting origin?
[英]How to scale a point relative to a specific point as origin, instead of origin (0,0)?
我有比例因子sf=[0.5,0.75,0.85,1,1.25,1.5,1.75,2]
,并且我想通过相对于比例缩放来计算点e=[70, 140]
sf=[0.5,0.75,0.85,1,1.25,1.5,1.75,2]
e=[70, 140]
(蓝线)的坐标python中的center_point=[89, 121]
(图片中的红色点)。
scaled_point_x = e[0] * sf[0]
scaled_point_y = e[1] * sf[0]
ee=[scaled_point_x,scaled_point_y] # yellow color line in the figure
添加中心点的坐标以转换为红色点(中心点)后,我得到黑线,这是不正确的
new=[scaled_point_x+center_point[0],scaled_point_y+center_point[1]]
我怎样才能解决这个问题? 我哪部分做错了?
这是一个数学问题,而不是编程问题。 为了相对于中心点cp
将点e
缩放为因子f
,
new_e = f*(e-cp)+cp
即,您可以缩放点和中心点之间的差异矢量,然后将其转换回中心。
此类问题可以在计算机图形书籍的第2章中解决。
尝试这个,
这是一些蟒蛇
scaled_pts = []
for s in sf:
tr_pointx, tr_pointy = e[0]-center_point[0], e[1]-center_point[1]
sc_pointx, sc_pointy = tr_pointx * s, tr_pointy * s
scaled_pt = [sc_pointx + center_point[0], sc_pointy + center_point[1]]
# draw the pt
scaled_pts.append(scaled_pt)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.