![](/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.