简体   繁体   English

如何在Python中缩放一条线的长度并获得相应的坐标((x1,y1),(x2,y2))?

[英]How can I scale the length of a line and obtain the corresponding co-ordinates ((x1, y1), (x2, y2)) in Python?

I have a line with 2 sets of co-ordinates (x1, y1) and (x2, y2) corresponding to points A and B. I can calculate the Euclidean distance (L2 norm) between these 2 points using:我有一条线,有两组坐标 (x1, y1) 和 (x2, y2) 对应于点 A 和 B。我可以使用以下方法计算这两个点之间的欧氏距离(L2 范数):


point_a = (189, 45)
point_b = (387, 614)
line= (point_a, point_b)
point_array = np.array(line)
distance = np.linalg.norm(point_array)
print('Euclidean distance = ', distance)```

How is it possible to obtain the co-ordinates for the line scaled about it's midpoint?
i.e. I would like to scale the length of the line but keep the angle.

For that you have to do it with the mid point like this.为此,你必须像这样用中点来做。

import numpy as np

# Define the two points as a NumPy array
points = np.array([[189, 45], [387, 614]])

# Calculate the midpoint of the line
midpoint = points.mean(axis=0)

# Calculate the scaling factor
scale_factor = 2

# Scale the coordinates of the two points about the midpoint
scaled_points = midpoint + (points - midpoint) * scale_factor

# Print the scaled points
print(scaled_points)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用两个端点 (x1,y1)(x2,y2) 为线条设置动画,但 line.set_data() function 似乎没有更新 x 和 y 坐标 - I am trying to animate a line using two endpoints (x1,y1)(x2,y2) but line.set_data() function doesn't seem to update x and y co-ordinates Python中如何将YOLO格式标注转换为x1,y1,x2,y2坐标? - How to convert YOLO format annotations to x1, y1, x2, y2 coordinates in Python? 如何将 x1、x2、y1、y2 数组转换为矩形顶点数组? - How do I turn x1, x2, y1, y2 array into rectangular vertices array? 如何将 numpy 数组 [(x1,y1),(x2,y2),(x3,y3),...(xn,yn)] 转换为 [(x1,y1,x1^2,y1^2),(x2 ,y2,x2^2,y2^2),…(xn,yn,xn^2,yn^2)] - How to convert a numpy array [(x1,y1),(x2,y2),(x3,y3),…(xn,yn)] to [(x1,y1,x1^2,y1^2),(x2,y2,x2^2,y2^2),…(xn,yn,xn^2,yn^2)] 如何使用matplotlib沿着指定半径的点(x1,y1)和(x2,y2)的长度绘制圆柱? - How to draw a cylinder using matplotlib along length of point (x1,y1) and (x2,y2) with specified radius? 如何从列表中表达 x1, y1, x2, y2 - How to express x1, y1, x2, y2 from a list 使用matplotlib.pyplot [[x1,y1],[x2,y2]]绘制点 - draw points using matplotlib.pyplot [[x1,y1],[x2,y2]] 通过完全控制自动将鼠标从 X1、Y1 移动到 X2、Y2 - Automate Mouse Movement from X1,Y1 to X2,Y2 with complete control 切片 numpy 数组的多个帧,具有多个 y1:y2, x1:x2 - Slice multiple frame of numpy array with multiple y1:y2, x1:x2 比较两个numpy数组:(x1,y1)和(x2,y2),以检查元素是否相交 - Comparing two numpy arrays: (x1, y1) and (x2, y2) to check whether elements intersect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM