简体   繁体   English

通过质心移动几何

[英]Moving Geometry by Centroid

I have a collection of points: 我有几点要点:

[[2000,3000], [2000,12000], [10000,120000], [10000,3000], [2000,3000]]

and it has a center at coordinates [6000, 7500] 它的中心在坐标[6000, 7500]

What is a way to shift all the coordinates around a new center [x_new, y_new] ? 如何将所有坐标围绕新中心[x_new, y_new] Example, if I wanted to shift all the x/y's around [0,0] instead of the current center but I want to retain the shape. 例如,如果我想将所有x / y都移到[0,0]而不是当前中心附近,但我想保留形状。

The shapes vertices are not always rectangles, I am just using that for a simple example. 形状顶点并不总是矩形,我只是将其用作简单示例。

I want to limit 3rd party modules to numpy and the standard python library. 我想将第三方模块限制为numpy和标准python库。

Thanks! 谢谢!

Shifting a group of points in lockstep is achieved by adding the same displacement vector to each of them. 通过将相同的位移矢量添加到每个点,可以一步步移动一组点。

This is easy using numpy 使用numpy很容易

import numpy as np
points = np.array([[2000,3000], [2000,12000], [10000,120000], [10000,3000], [2000,3000]])
com = np.mean(points, axis=0)
delta = np.array((0, 0)) - com
shifted_points = points + delta

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM