[英]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.