我正在执行一项任务,在这个任务中,我必须将点云的节点(X和Y坐标)投影到网格(几何学)重心上的圆周。我的问题是,如何在几何上创建一个圆周,并将其划分为36个不同的部分,然后如何将节点投影到上面。
我已经找到了几何学的质心(地心引力中心)。我用它的质心移动了几何图形,并将它放置在参考点(0,0)上。现在我有相同的几何学,但是有不同的坐标,我在下面展示了。
node_number X_coordinate Y_coordinate
0 -1.0 -2.0
1 -1.0 -1.0
2 -1.0 0.0
3 -1.0 1.0
4 -2.0 1.0
5 -2.0 2.0
6 -1.0 2.0
7 0.0 2.0
8 1.0 2.0
9 2.0 2.0
10 2.0 1.0
11 1.0 1.0
12 0.0 1.0
13 0.0 0.0
14 0.0 -1.0
15 0.0 -2.0我想将节点(上面所示的坐标)投影到圆周上,该圆周被划分为36个像素(部分)。我在下面的图片中给出了一个例子.在这里输入图像描述
发布于 2022-08-20 18:56:46
以θ角绘制单位长度半径并不难。是时候开始读书了,是时候读SohCahToa了。
我包括几个你的例子要点。点m在网格上,c点在单位圆上。
请注意,您包括(0,0)作为一个网格点,并且atan2任意地为它选择了一个零的角度。在这种情况下,您可能更愿意抛出一个异常。用一个小的随机量移动整个网格将是避免模糊的一种策略。
import math
mesh_points = [
(-1, -2),
(-1, -1),
(0, 0),
(0, -2),
]
def projection_onto_circle(mesh_points, r=1, epsilon=1e-6):
"""Projects a container of mesh points onto a circle.
Defaults to using a unit circle.
Mesh points should be specified w.r.t.
a suitable origin, e.g. the mesh centroid.
"""
for x_m, y_m in mesh_points:
theta = math.atan2(y_m, x_m)
x_c = r * math.cos(theta)
y_c = r * math.sin(theta)
plot(x_c, y_c)
assert abs(r - math.sqrt(x_c ** 2 + y_c ** 2)) < epsilon
def draw_circle(num_points=36, r=1):
"""Draw equidistant points along the circumference of a circle.
"""
inc = 360 / num_points
for i in range(0, num_points + 1):
deg = i * inc
theta = math.radians(deg)
x = r * math.cos(theta)
y = r * math.sin(theta)
plot(x, y)
def plot(x, y):
"""Stub, for displaying points on matplotlib axes,
HTML5 or tk canvas.
"""
print(f'({x:.03f}, {y:.03f})')https://stackoverflow.com/questions/73427933
复制相似问题