简体   繁体   English

如何缩放相对于特定点的点作为原点,而不是原点(0,0)?

[英]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, 尝试这个,

  1. translate the center_point to origin ie subtract centre_point from point 将center_point转换为原点,即从点减去center_point
  2. scale the point ie multiply by sf 缩放点,即乘以sf
  3. translate the center_point to original position ie add center_point to point 将center_point转换为原始位置,即将center_point添加到点

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.

相关问题 在 python random walker 中,如何设置随机起点而不是设置原点? - In python random walker ,how can I set a random starting point instead of setting origin? Python位屏蔽和点簇/原点组 - Python bitmasking and point cluster/group of origin 无法删除matplotlib polycollection中的原点 - couldn't remove origin point in matplotlib polycollection PyQT5 setRect 在 QGraphicsScene 中移动原点 - PyQT5 setRect moves origin point in a QGraphicsScene 在圆上绘制点,每个点根据出现的频率远离原点。 怪异的行为 - Plotting points on a circle, where each point is further from the origin based on how often it is present. Weird behavior 我如何在 plot 中使用 matlotlib 在 3d plot 中从同一原点开始多条线? - How do i plot multiple lines from a same point of origin in a 3d plot using matlotlib in python? 让 matplotlib 图表轴在原点 (0,0) 相交 - Getting matplotlib chart axes to intersect at the Origin (0,0) 如何设置中心和半径的默认值Point(0,0)= 1? - How do I set the default value Point(0,0) for center and radius = 1? 使用 Python 从原点和终点创建矩形的正确方法是什么? - What's the correct way to create a rectangle from an origin point and an end point with Python? 如何用python中的topLeft点(0,0)和bottomRight点(1,1)两点初始化矩形类? - How does one initialize a rectangle class with two points, topLeft point (0,0) and bottomRight point (1,1) in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM