如何缩放相对于特定点作为原点而不是原点(0,0)的点?
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]
,我想通过相对于 center_point=[89, 121]
(图中的红点)缩放来计算点 e=[70, 140]
(蓝线)的坐标图片)在 python 中。
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
、
按因子 f
缩放点 e
new_e = f*(e-cp)+cp
即您缩放点和中心点之间的差异向量,然后将其平移回中心。
此类问题可能会在计算机图形学书籍的第 2 章中解决。
试试这个,
- 将 center_point 转换为原点,即从点
中减去 centre_point
- 缩放点,即乘以 sf
- 将 center_point 翻译到原始位置,即添加 center_point 到点
这里有一些 python
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)
我有缩放因子 sf=[0.5,0.75,0.85,1,1.25,1.5,1.75,2]
,我想通过相对于 center_point=[89, 121]
(图中的红点)缩放来计算点 e=[70, 140]
(蓝线)的坐标图片)在 python 中。
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
、
f
缩放点 e
new_e = f*(e-cp)+cp
即您缩放点和中心点之间的差异向量,然后将其平移回中心。
此类问题可能会在计算机图形学书籍的第 2 章中解决。
试试这个,
- 将 center_point 转换为原点,即从点 中减去 centre_point
- 缩放点,即乘以 sf
- 将 center_point 翻译到原始位置,即添加 center_point 到点
这里有一些 python
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)