[英]How to scale a point relative to a specific point as origin, instead of origin (0,0)?
I have the scaling factors sf=[0.5,0.75,0.85,1,1.25,1.5,1.75,2]
, and I want to calculate the coordinates of the point e=[70, 140]
(blue line) by scaling relative to the center_point=[89, 121]
(red point in the picture) in python. 我有比例因子
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
After adding the coordinate of center point to translate to the red point (center point), I get black line, which is not correct 添加中心点的坐标以转换为红色点(中心点)后,我得到黑线,这是不正确的
new=[scaled_point_x+center_point[0],scaled_point_y+center_point[1]]
How can I fix this? 我怎样才能解决这个问题? which part am I doing wrong?
我哪部分做错了?
This is rather a math question than a programming question. 这是一个数学问题,而不是编程问题。 To scale a point
e
by a factor f
with respect to a center point cp
, 为了相对于中心点
cp
将点e
缩放为因子f
,
new_e = f*(e-cp)+cp
ie you scale the difference vector between the point and the center point and then translate it back to the center. 即,您可以缩放点和中心点之间的差异矢量,然后将其转换回中心。
This sort of problem maybe tackled in chapter 2 of computer graphics books. 此类问题可以在计算机图形书籍的第2章中解决。
Try this, 尝试这个,
here is some 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.