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.
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
,
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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.