Ma trận biến đổi python
Hãy tưởng tượng bạn có một nhóm các vectơ, e. g. dưới dạng quỹ đạo. Có cách nào được vector hóa để áp dụng ma trận chuyển đổi cho tất cả các điểm dữ liệu cùng một lúc hay bạn bị mắc kẹt với vòng lặp for?
Tất cả những gì tôi tìm thấy cho đến nay là >>> alpha, beta, gamma = 0.123, -1.234, 2.345 >>> origin, xaxis, yaxis, zaxis = (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1) >>> I = identity_matrix() >>> Rx = rotation_matrix(alpha, xaxis) >>> Ry = rotation_matrix(beta, yaxis) >>> Rz = rotation_matrix(gamma, zaxis) >>> R = concatenate_matrices(Rx, Ry, Rz) >>> euler = euler_from_matrix(R, 'rxyz') >>> numpy.allclose([alpha, beta, gamma], euler) True >>> Re = euler_matrix(alpha, beta, gamma, 'rxyz') >>> is_same_transform(R, Re) True >>> al, be, ga = euler_from_matrix(Re, 'rxyz') >>> is_same_transform(Re, euler_matrix(al, be, ga, 'rxyz')) True >>> qx = quaternion_about_axis(alpha, xaxis) >>> qy = quaternion_about_axis(beta, yaxis) >>> qz = quaternion_about_axis(gamma, zaxis) >>> q = quaternion_multiply(qx, qy) >>> q = quaternion_multiply(q, qz) >>> Rq = quaternion_matrix(q) >>> is_same_transform(R, Rq) True >>> S = scale_matrix(1.23, origin) >>> T = translation_matrix((1, 2, 3)) >>> Z = shear_matrix(beta, xaxis, origin, zaxis) >>> R = random_rotation_matrix(numpy.random.rand(3)) >>> M = concatenate_matrices(T, R, Z, S) >>> scale, shear, angles, trans, persp = decompose_matrix(M) >>> numpy.allclose(scale, 1.23) True >>> numpy.allclose(trans, (1, 2, 3)) True >>> numpy.allclose(shear, (0, math.tan(beta), 0)) True >>> is_same_transform(R, euler_matrix(axes='sxyz', *angles)) True >>> M1 = compose_matrix(scale, shear, angles, trans, persp) >>> is_same_transform(M, M1) True7 và hai bài đăng này (một, hai), dường như không có bài đăng nào áp dụng cho trường hợp của tôi Hình dạng mới phải tương thích với hình dạng ban đầu. Nếu là một số nguyên, thì kết quả sẽ là một mảng 1-D có độ dài đó. Một kích thước hình dạng có thể là -1. Trong trường hợp này, giá trị được suy ra từ độ dài của mảng và các kích thước còn lại thứ tự {'C', 'F', 'A'}, tùy chọnĐọc các phần tử của a bằng cách sử dụng thứ tự chỉ mục này và đặt các phần tử vào mảng được định hình lại bằng cách sử dụng thứ tự chỉ mục này. 'C' có nghĩa là đọc/ghi các phần tử theo thứ tự chỉ mục giống như C, với chỉ mục trục cuối cùng thay đổi nhanh nhất, trở lại chỉ mục trục đầu tiên thay đổi chậm nhất. 'F' có nghĩa là đọc/ghi các phần tử theo thứ tự chỉ mục giống như Fortran, với chỉ mục đầu tiên thay đổi nhanh nhất và chỉ mục cuối cùng thay đổi chậm nhất. Lưu ý rằng các tùy chọn 'C' và 'F' không tính đến bố cục bộ nhớ của mảng bên dưới và chỉ đề cập đến thứ tự lập chỉ mục. 'A' có nghĩa là đọc/ghi các phần tử theo thứ tự chỉ mục giống Fortran nếu a là Fortran liền kề trong bộ nhớ, thứ tự giống C nếu không Trả về . reshape_array ndarrayĐây sẽ là một đối tượng xem mới nếu có thể; . Lưu ý rằng không có gì đảm bảo về cách bố trí bộ nhớ (C- hoặc Fortran- liền kề) của mảng được trả về Xem thêm >>> alpha, beta, gamma = 0.123, -1.234, 2.345 >>> origin, xaxis, yaxis, zaxis = (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1) >>> I = identity_matrix() >>> Rx = rotation_matrix(alpha, xaxis) >>> Ry = rotation_matrix(beta, yaxis) >>> Rz = rotation_matrix(gamma, zaxis) >>> R = concatenate_matrices(Rx, Ry, Rz) >>> euler = euler_from_matrix(R, 'rxyz') >>> numpy.allclose([alpha, beta, gamma], euler) True >>> Re = euler_matrix(alpha, beta, gamma, 'rxyz') >>> is_same_transform(R, Re) True >>> al, be, ga = euler_from_matrix(Re, 'rxyz') >>> is_same_transform(Re, euler_matrix(al, be, ga, 'rxyz')) True >>> qx = quaternion_about_axis(alpha, xaxis) >>> qy = quaternion_about_axis(beta, yaxis) >>> qz = quaternion_about_axis(gamma, zaxis) >>> q = quaternion_multiply(qx, qy) >>> q = quaternion_multiply(q, qz) >>> Rq = quaternion_matrix(q) >>> is_same_transform(R, Rq) True >>> S = scale_matrix(1.23, origin) >>> T = translation_matrix((1, 2, 3)) >>> Z = shear_matrix(beta, xaxis, origin, zaxis) >>> R = random_rotation_matrix(numpy.random.rand(3)) >>> M = concatenate_matrices(T, R, Z, S) >>> scale, shear, angles, trans, persp = decompose_matrix(M) >>> numpy.allclose(scale, 1.23) True >>> numpy.allclose(trans, (1, 2, 3)) True >>> numpy.allclose(shear, (0, math.tan(beta), 0)) True >>> is_same_transform(R, euler_matrix(axes='sxyz', *angles)) True >>> M1 = compose_matrix(scale, shear, angles, trans, persp) >>> is_same_transform(M, M1) True8 phương pháp tương đương ghi chú Không phải lúc nào cũng có thể thay đổi hình dạng của một mảng mà không cần sao chép dữ liệu. Muốn báo lỗi khi copy dữ liệu thì gán shape mới cho thuộc tính shape của mảng >>> a = np.zeros((10, 2)) # A transpose makes the array non-contiguous >>> b = a.T # Taking a view makes it possible to modify the shape without modifying # the initial object. >>> c = b.view() >>> c.shape = (20) Traceback (most recent call last): ... AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape. Từ khóa order cung cấp chỉ mục sắp xếp cả hai để tìm nạp các giá trị từ a, sau đó đặt các giá trị vào mảng đầu ra. Ví dụ: giả sử bạn có một mảng >>> a = np.arange(6).reshape((3, 2)) >>> a array([[0, 1], [2, 3], [4, 5]]) Bạn có thể nghĩ về việc định hình lại giống như việc sắp xếp lại mảng trước tiên (sử dụng thứ tự chỉ mục đã cho), sau đó chèn các phần tử từ mảng đã sắp xếp lại vào mảng mới bằng cách sử dụng cùng một loại thứ tự chỉ mục như đã được sử dụng để sắp xếp lại >>> alpha, beta, gamma = 0.123, -1.234, 2.345 >>> origin, xaxis, yaxis, zaxis = (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1) >>> I = identity_matrix() >>> Rx = rotation_matrix(alpha, xaxis) >>> Ry = rotation_matrix(beta, yaxis) >>> Rz = rotation_matrix(gamma, zaxis) >>> R = concatenate_matrices(Rx, Ry, Rz) >>> euler = euler_from_matrix(R, 'rxyz') >>> numpy.allclose([alpha, beta, gamma], euler) True >>> Re = euler_matrix(alpha, beta, gamma, 'rxyz') >>> is_same_transform(R, Re) True >>> al, be, ga = euler_from_matrix(Re, 'rxyz') >>> is_same_transform(Re, euler_matrix(al, be, ga, 'rxyz')) True >>> qx = quaternion_about_axis(alpha, xaxis) >>> qy = quaternion_about_axis(beta, yaxis) >>> qz = quaternion_about_axis(gamma, zaxis) >>> q = quaternion_multiply(qx, qy) >>> q = quaternion_multiply(q, qz) >>> Rq = quaternion_matrix(q) >>> is_same_transform(R, Rq) True >>> S = scale_matrix(1.23, origin) >>> T = translation_matrix((1, 2, 3)) >>> Z = shear_matrix(beta, xaxis, origin, zaxis) >>> R = random_rotation_matrix(numpy.random.rand(3)) >>> M = concatenate_matrices(T, R, Z, S) >>> scale, shear, angles, trans, persp = decompose_matrix(M) >>> numpy.allclose(scale, 1.23) True >>> numpy.allclose(trans, (1, 2, 3)) True >>> numpy.allclose(shear, (0, math.tan(beta), 0)) True >>> is_same_transform(R, euler_matrix(axes='sxyz', *angles)) True >>> M1 = compose_matrix(scale, shear, angles, trans, persp) >>> is_same_transform(M, M1) True9 và >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()0 lần lượt thực hiện biến đổi Fourier và biến đổi Fourier ngược. Đối với >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()1 và >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()2 có độ dài >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()3, các phép biến đổi này được định nghĩa như sau Y(k)=∑j=1nX(j) An(j−1)(k−1)X(j)=1 n∑k=1nY(k) An−(j−1)(k−1 ở đâu là một trong n gốc của sự thống nhất Một thư viện để tính toán các ma trận 4x4 để tịnh tiến, xoay, phản xạ, chia tỷ lệ, cắt, chiếu, trực giao hóa và xếp chồng các mảng tọa độ đồng nhất 3D cũng như để chuyển đổi giữa các ma trận xoay, góc Euler và bậc bốn. Cũng bao gồm một đối tượng điều khiển Arcball và các chức năng để phân tách các ma trận biến đổi tác giả. Christoph Gohlke, Phòng thí nghiệm Động lực huỳnh quang, Đại học California, IrvineVersion. 20090418Yêu cầu¶
Ghi chú¶Ma trận (M) có thể được đảo ngược bằng cách sử dụng numpy. linalg. inv(M), nối với nhau bằng cách sử dụng numpy. dot(M0, M1) hoặc được sử dụng để biến đổi tọa độ thuần nhất (v) bằng cách sử dụng numpy. dot(M, v) cho shape (4, *) “điểm của mảng”, tương ứng là numpy. dấu chấm(v, M. T) cho hình dạng (*, 4) “mảng điểm” Tính toán được thực hiện với numpy. độ chính xác float64 Việc triển khai Python này không được tối ưu hóa cho tốc độ Các đối số của hàm véc-tơ, điểm, bậc bốn và ma trận được cho là “giống như mảng”, tôi. e. mảng tuple, list hoặc numpy Các kiểu trả về là các mảng có nhiều mảng trừ khi được chỉ định khác Các góc tính bằng radian trừ khi có quy định khác Bậc bốn ix+jy+kz+w được biểu diễn dưới dạng [x, y, z, w] Sử dụng chuyển vị của ma trận chuyển đổi cho OpenGL glMultMatrixd() Bộ ba góc Euler có thể được áp dụng/giải thích theo 24 cách, có thể được chỉ định bằng cách sử dụng chuỗi 4 ký tự hoặc bộ 4 được mã hóa
Người giới thiệu¶
Ví dụ¶>>> alpha, beta, gamma = 0.123, -1.234, 2.345 >>> origin, xaxis, yaxis, zaxis = (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1) >>> I = identity_matrix() >>> Rx = rotation_matrix(alpha, xaxis) >>> Ry = rotation_matrix(beta, yaxis) >>> Rz = rotation_matrix(gamma, zaxis) >>> R = concatenate_matrices(Rx, Ry, Rz) >>> euler = euler_from_matrix(R, 'rxyz') >>> numpy.allclose([alpha, beta, gamma], euler) True >>> Re = euler_matrix(alpha, beta, gamma, 'rxyz') >>> is_same_transform(R, Re) True >>> al, be, ga = euler_from_matrix(Re, 'rxyz') >>> is_same_transform(Re, euler_matrix(al, be, ga, 'rxyz')) True >>> qx = quaternion_about_axis(alpha, xaxis) >>> qy = quaternion_about_axis(beta, yaxis) >>> qz = quaternion_about_axis(gamma, zaxis) >>> q = quaternion_multiply(qx, qy) >>> q = quaternion_multiply(q, qz) >>> Rq = quaternion_matrix(q) >>> is_same_transform(R, Rq) True >>> S = scale_matrix(1.23, origin) >>> T = translation_matrix((1, 2, 3)) >>> Z = shear_matrix(beta, xaxis, origin, zaxis) >>> R = random_rotation_matrix(numpy.random.rand(3)) >>> M = concatenate_matrices(T, R, Z, S) >>> scale, shear, angles, trans, persp = decompose_matrix(M) >>> numpy.allclose(scale, 1.23) True >>> numpy.allclose(trans, (1, 2, 3)) True >>> numpy.allclose(shear, (0, math.tan(beta), 0)) True >>> is_same_transform(R, euler_matrix(axes='sxyz', *angles)) True >>> M1 = compose_matrix(scale, shear, angles, trans, persp) >>> is_same_transform(M, M1) Truelớp tf. phép biến hình. Arcball(initial=None)¶ Điều khiển bi xoay ảo >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()xuống (điểm)¶ Đặt tọa độ cửa sổ con trỏ ban đầu và chọn trục giới hạn Cập nhật tọa độ cửa sổ con trỏ hiện tại getconstrain()¶Trả lại trạng thái ràng buộc cho chế độ trục ma trận()¶Trả về ma trận quay thuần nhất tiếp theo (gia tốc = 0. 0)¶Tiếp tục xoay theo hướng kéo cuối cùng vị trí (tâm, bán kính)¶Đặt Arcball, e. g. khi kích thước cửa sổ thay đổi trung tâm . sequence[2] Tọa độ cửa sổ của tâm bi xoay. bán kính . float Bán kính bi xoay trong tọa độ cửa sổ. setaxes(*axes)¶Đặt trục để hạn chế xoay setconstrain(ràng buộc)¶Đặt trạng thái ràng buộc thành chế độ trục tf. phép biến đổi. arcball_constrain_to_axis(điểm, trục)¶Trả về điểm hình cầu vuông góc với trục tf. phép biến hình. arcball_map_to_sphere(điểm, tâm, bán kính)¶Trả về tọa độ hình cầu đơn vị từ tọa độ cửa sổ tf. phép biến hình. arcball_gần_axis(điểm, trục)¶Trục trả về, cung nào gần điểm nhất tf. phép biến đổi. clip_matrix(trái, phải, dưới, trên, gần, xa, phối cảnh=Sai)¶Trả về ma trận để lấy tọa độ thiết bị đã chuẩn hóa từ sự thất vọng Các giới hạn của sự thất vọng được căn chỉnh theo trục dọc theo x (trái, phải), y (dưới cùng, trên cùng) và z (gần, xa) Tọa độ của thiết bị được chuẩn hóa nằm trong khoảng [-1, 1] nếu tọa độ nằm trong phạm vi Nếu phối cảnh là Đúng thì phần thất vọng là một kim tự tháp cắt ngắn với điểm phối cảnh tại gốc và hướng dọc theo trục z, nếu không thì một khối chế độ xem chính tắc trực giao (một hộp) Các tọa độ đồng nhất được chuyển đổi bởi ma trận clip phối cảnh cần phải được đồng nhất (chia cho tọa độ w) >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])tf. phép biến hình. soạn_matrix(tỷ lệ=Không, cắt=Không, góc=Không, dịch=Không, phối cảnh=Không)¶ Trả về ma trận biến đổi từ chuỗi biến đổi Đây là nghịch đảo của hàm phân hủy_ma trận Chuỗi biến đổi. tỉ lệ. véc tơ của 3 yếu tố tỷ lệ cắt. danh sách các yếu tố cắt cho các góc trục x-y, x-z, y-z. danh sách các góc Euler về các trục x, y, z tĩnh tịnh tiến. vectơ tịnh tiến dọc theo phối cảnh trục x, y, z. phân vùng phối cảnh của ma trận>>> scale = numpy.random.random(3) - 0.5 >>> shear = numpy.random.random(3) - 0.5 >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi) >>> trans = numpy.random.random(3) - 0.5 >>> persp = numpy.random.random(4) - 0.5 >>> M0 = compose_matrix(scale, shear, angles, trans, persp) >>> result = decompose_matrix(M0) >>> M1 = compose_matrix(*result) >>> is_same_transform(M0, M1) Truetf. phép biến hình. concatenate_matrices(*matrics)¶ Trả về phép nối của chuỗi ma trận biến đổi >>> M = numpy.random.rand(16).reshape((4, 4)) - 0.5 >>> numpy.allclose(M, concatenate_matrices(M)) True >>> numpy.allclose(numpy.dot(M, M.T), concatenate_matrices(M, M.T)) Truetf. phép biến hình. phân rã_ma trận(ma trận)¶ Trả về chuỗi các phép biến đổi từ ma trận biến đổi ma trận . array_like Ma trận biến đổi thuần nhất không suy biếnReturn tuple of. tỉ lệ. véc tơ của 3 yếu tố tỷ lệ cắt. danh sách các yếu tố cắt cho các góc trục x-y, x-z, y-z. danh sách các góc Euler về các trục x, y, z tĩnh tịnh tiến. vectơ tịnh tiến dọc theo phối cảnh trục x, y, z. phân vùng phối cảnh của ma trậnTăng giá trịError nếu ma trận sai loại hoặc suy biến ________số 8 tf. phép biến hình. euler_from_matrix(ma trận, trục='sxyz')¶Trả về các góc Euler từ ma trận xoay cho chuỗi trục đã chỉ định trục. Một trong 24 chuỗi trục dưới dạng chuỗi hoặc bộ được mã hóa Lưu ý rằng nhiều bộ ba góc Euler có thể mô tả một ma trận >>> R0 = euler_matrix(1, 2, 3, 'syxz') >>> al, be, ga = euler_from_matrix(R0, 'syxz') >>> R1 = euler_matrix(al, be, ga, 'syxz') >>> numpy.allclose(R0, R1) True >>> angles = (4.0*math.pi) * (numpy.random.random(3) - 0.5) >>> for axes in _AXES2TUPLE.keys(): .. R0 = euler_matrix(axes=axes, *angles) .. R1 = euler_matrix(axes=axes, *euler_from_matrix(R0, axes)) .. if not numpy.allclose(R0, R1): print axes, "failed"tf. phép biến đổi. euler_from_quaternion(bậc bốn, trục='sxyz')¶ Trả về các góc Euler từ quaternion cho chuỗi trục đã chỉ định >>> a = np.zeros((10, 2)) # A transpose makes the array non-contiguous >>> b = a.T # Taking a view makes it possible to modify the shape without modifying # the initial object. >>> c = b.view() >>> c.shape = (20) Traceback (most recent call last): ... AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape.0tf. phép biến hình. euler_matrix(ai, aj, ak, trục='sxyz')¶ Trả về ma trận quay đồng nhất từ góc Euler và chuỗi trục ai, aj, ak. Các trục góc cuộn, cao độ và nghiêng của Euler. Một trong 24 chuỗi trục dưới dạng chuỗi hoặc bộ được mã hóa >>> a = np.zeros((10, 2)) # A transpose makes the array non-contiguous >>> b = a.T # Taking a view makes it possible to modify the shape without modifying # the initial object. >>> c = b.view() >>> c.shape = (20) Traceback (most recent call last): ... AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape.1tf. phép biến hình. ma trận đơn vị()¶ Trả về ma trận đơn vị/đơn vị 4x4 >>> a = np.zeros((10, 2)) # A transpose makes the array non-contiguous >>> b = a.T # Taking a view makes it possible to modify the shape without modifying # the initial object. >>> c = b.view() >>> c.shape = (20) Traceback (most recent call last): ... AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape.2 Trả về nghịch đảo của ma trận biến đổi vuông >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()0tf. phép biến đổi. is_same_transform(ma trận0, ma trận1)¶ Trả về True nếu hai ma trận thực hiện cùng một phép biến đổi >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()1tf. phép biến hình. orthogonalization_matrix(độ dài, góc)¶ Trả về ma trận trực giao cho tọa độ tế bào tinh thể Các góc được mong đợi tính bằng độ Ma trận khử trực giao là ma trận nghịch đảo >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()2tf. phép biến hình. phép chiếu_từ_ma trận(ma trận, giả=Sai)¶ Trả về mặt phẳng chiếu và điểm phối cảnh từ ma trận chiếu Giá trị trả về giống như đối số cho hàm projector_matrix. điểm, bình thường, hướng, phối cảnh và giả >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()3tf. phép biến hình. projector_matrix(điểm, bình thường, hướng=Không, phối cảnh=Không, giả=Sai)¶ Trả lại ma trận để chiếu lên mặt phẳng được xác định bởi điểm và bình thường Sử dụng một trong hai điểm phối cảnh, hướng chiếu hoặc không sử dụng cả hai Nếu pseudo là True, các phép chiếu phối cảnh sẽ bảo toàn độ sâu tương đối sao cho Perspective = dot(Orthogonal, PseudoPerspective) >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()4tf. phép biến hình. quaternion_about_axis(góc, trục)¶ Trả về bậc bốn cho phép quay quanh trục >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()5tf. phép biến đổi. quaternion_conjugate(quaternion)¶ Trả về liên hợp của quaternion >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()6tf. phép biến hình. quaternion_from_euler(ai, aj, ak, axis='sxyz')¶ Trả về quaternion từ các góc Euler và chuỗi trục ai, aj, ak. Các trục góc cuộn, cao độ và nghiêng của Euler. Một trong 24 chuỗi trục dưới dạng chuỗi hoặc bộ được mã hóa >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()7tf. phép biến hình. quaternion_from_matrix(ma trận)¶ Trả về quaternion từ ma trận xoay >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()8tf. phép biến đổi. quaternion_inverse(quaternion)¶ Trả về nghịch đảo của quaternion >>> ball = Arcball() >>> ball = Arcball(initial=numpy.identity(4)) >>> ball.place([320, 320], 320) >>> ball.down([500, 250]) >>> ball.drag([475, 275]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 3.90583455) True >>> ball = Arcball(initial=[0, 0, 0, 1]) >>> ball.place([320, 320], 320) >>> ball.setaxes([1,1,0], [-1, 1, 0]) >>> ball.setconstrain(True) >>> ball.down([400, 200]) >>> ball.drag([200, 400]) >>> R = ball.matrix() >>> numpy.allclose(numpy.sum(R), 0.2055924) True >>> ball.next()9tf. phép biến hình. quaternion_matrix(quaternion)¶ Trả về ma trận xoay đồng nhất từ quaternion >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])0tf. phép biến đổi. quaternion_multiply(quaternion1, quaternion0)¶ Trả về phép nhân hai bậc bốn >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])1tf. phép biến hình. quaternion_slerp(quat0, quat1, phân số, spin=0, đường đi ngắn nhất=True)¶ Trả về phép nội suy tuyến tính hình cầu giữa hai bậc bốn >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])2tf. phép biến đổi. random_quaternion(rand=None)¶ Trả về đơn vị ngẫu nhiên thống nhất quaternion rand. mảng như thế nào hoặc Không có Ba biến ngẫu nhiên độc lập được phân phối đồng đều giữa 0 và 1>>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])3tf. phép biến đổi. random_rotation_matrix(rand=None)¶ Trả về ma trận xoay ngẫu nhiên thống nhất lần thứ hai. giống như mảngBa biến ngẫu nhiên độc lập được phân phối đồng đều từ 0 đến 1 cho mỗi bậc bốn được trả về>>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])4tf. phép biến hình. random_vector(size)¶ Trả về mảng nhân đôi ngẫu nhiên trong khoảng thời gian nửa mở [0. 0, 1. 0) >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])5tf. phép biến hình. phản xạ_từ_ma trận(ma trận)¶ Trả về điểm mặt phẳng gương và vectơ pháp tuyến từ ma trận phản xạ >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])6tf. phép biến hình. Reflection_matrix(điểm, bình thường)¶ Đưa ma trận về gương tại mặt phẳng được xác định bởi điểm và vectơ pháp tuyến >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])7tf. phép biến đổi. xoay_từ_ma trận(ma trận)¶ Trả về góc quay và trục từ ma trận xoay >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])8tf. phép biến đổi. rotate_matrix(góc, hướng, điểm=Không)¶ Trả về ma trận để xoay quanh trục được xác định bởi điểm và hướng >>> frustrum = numpy.random.rand(6) >>> frustrum[1] += frustrum[0] >>> frustrum[3] += frustrum[2] >>> frustrum[5] += frustrum[4] >>> M = clip_matrix(*frustrum, perspective=False) >>> numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) array([-1., -1., -1., 1.]) >>> numpy.dot(M, [frustrum[1], frustrum[3], frustrum[5], 1.0]) array([ 1., 1., 1., 1.]) >>> M = clip_matrix(*frustrum, perspective=True) >>> v = numpy.dot(M, [frustrum[0], frustrum[2], frustrum[4], 1.0]) >>> v / v[3] array([-1., -1., -1., 1.]) >>> v = numpy.dot(M, [frustrum[1], frustrum[3], frustrum[4], 1.0]) >>> v / v[3] array([ 1., 1., -1., 1.])9tf. phép biến hình. scale_from_matrix(ma trận)¶ Trả về hệ số tỷ lệ, nguồn gốc và hướng từ ma trận tỷ lệ >>> scale = numpy.random.random(3) - 0.5 >>> shear = numpy.random.random(3) - 0.5 >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi) >>> trans = numpy.random.random(3) - 0.5 >>> persp = numpy.random.random(4) - 0.5 >>> M0 = compose_matrix(scale, shear, angles, trans, persp) >>> result = decompose_matrix(M0) >>> M1 = compose_matrix(*result) >>> is_same_transform(M0, M1) True0tf. phép biến hình. scale_matrix(yếu tố, gốc=Không, hướng=Không)¶ Đưa ma trận về tỷ lệ theo hệ số quanh gốc theo hướng Sử dụng hệ số -1 cho điểm đối xứng >>> scale = numpy.random.random(3) - 0.5 >>> shear = numpy.random.random(3) - 0.5 >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi) >>> trans = numpy.random.random(3) - 0.5 >>> persp = numpy.random.random(4) - 0.5 >>> M0 = compose_matrix(scale, shear, angles, trans, persp) >>> result = decompose_matrix(M0) >>> M1 = compose_matrix(*result) >>> is_same_transform(M0, M1) True1tf. phép biến đổi. shear_from_matrix(ma trận)¶ Trả về góc cắt, hướng và mặt phẳng từ ma trận cắt >>> scale = numpy.random.random(3) - 0.5 >>> shear = numpy.random.random(3) - 0.5 >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi) >>> trans = numpy.random.random(3) - 0.5 >>> persp = numpy.random.random(4) - 0.5 >>> M0 = compose_matrix(scale, shear, angles, trans, persp) >>> result = decompose_matrix(M0) >>> M1 = compose_matrix(*result) >>> is_same_transform(M0, M1) True2tf. phép biến đổi. shear_matrix(góc, hướng, điểm, pháp tuyến)¶ Đưa ma trận về lực cắt theo góc dọc theo vectơ chỉ hướng trên mặt phẳng cắt Mặt phẳng cắt được xác định bởi một điểm và vectơ pháp tuyến. Vectơ chỉ phương phải trực giao với vectơ pháp tuyến của mặt phẳng Một điểm P được biến đổi bởi ma trận trượt thành P” sao cho vectơ P-P” song song với vectơ chỉ phương và phạm vi của nó được cho bởi góc của P-P'-P”, trong đó P' là hình chiếu trực giao của P >>> scale = numpy.random.random(3) - 0.5 >>> shear = numpy.random.random(3) - 0.5 >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi) >>> trans = numpy.random.random(3) - 0.5 >>> persp = numpy.random.random(4) - 0.5 >>> M0 = compose_matrix(scale, shear, angles, trans, persp) >>> result = decompose_matrix(M0) >>> M1 = compose_matrix(*result) >>> is_same_transform(M0, M1) True3tf. phép biến đổi. superimposition_matrix(v0, v1, Scaling=False, usedvd=True)¶ Trả về ma trận để chuyển đổi tập hợp vectơ đã cho thành tập hợp vectơ thứ hai v0 và v1 là các mảng hình dạng (3, *) hoặc (4, *) của ít nhất 3 vectơ Nếu sử dụngvd là Đúng, tổng trọng số của độ lệch bình phương (RMSD) được giảm thiểu theo thuật toán bởi W. Kabsch [8]. Mặt khác, thuật toán dựa trên quaternion của B. Horn [9] được sử dụng (chậm hơn khi sử dụng triển khai Python này) |