def rotate_points(points, axis, angle, origin=None): """Rotates points around an arbitrary axis in 3D (radians). Parameters: points (sequence of sequence of float): XYZ coordinates of the points. axis (sequence of float): The rotation axis. angle (float): the angle of rotation in radians. origin (sequence of float): Optional. The origin of the rotation axis. Default is ``[0.0, 0.0, 0.0]``. Returns: list: the rotated points References: https://en.wikipedia.org/wiki/Rotation_matrix """ R = rotation_matrix(angle, axis, origin) points = transform(points, R) return points
cloud[:, 1] *= - 3.0 cloud[:, 1] -= 3.0 axis[1] = -1 else: cloud[:, 1] *= 3.0 cloud[:, 1] += 3.0 if i in (4, 5, 6, 7): cloud[:, 2] *= - 6.0 cloud[:, 2] -= 3.0 axis[2] = -1 else: cloud[:, 2] *= 6.0 cloud[:, 2] += 3.0 R = rotation_matrix(angle, axis) cloud[:] = transform(cloud, R) clouds.append(cloud.tolist()) cloud = [point for points in clouds for point in points] centroids, _ = kmeans(cloud, 8) idx, _ = vq(cloud, centroids) print(idx) for i, point in zip(idx, cloud): print(i, point) axes = create_axes_3d()
from compas.numerical.transformations import transform from compas.visualization.plotters.helpers import Axes3D from compas.visualization.plotters.helpers import Cloud3D from compas.visualization.plotters.helpers import Bounds from compas.visualization.plotters.drawing import create_axes_3d from compas.numerical.statistics import principal_components data = random.rand(300, 3) data[:, 0] *= 10.0 data[:, 1] *= 1.0 data[:, 2] *= 4.0 a = 3.14159 * 30.0 / 180 Ry = rotation_matrix(a, [0, 1.0, 0.0]) a = -3.14159 * 45.0 / 180 Rz = rotation_matrix(a, [0, 0, 1.0]) R = Rz.dot(Ry) data = transform(data, R) average, vectors, values = principal_components(data) axes = create_axes_3d() Bounds(data).plot(axes) Cloud3D(data).plot(axes) Axes3D(average, vectors).plot(axes)