python rotate_func.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python rotate_func.py相关的知识,希望对你有一定的参考价值。

def rotate(row, angle, dim1, dim2):
    radian = angle * pi / 180.
    cos_alpha, sin_alpha = cos(radian), sin(radian)
    x, y = row[dim1], row[dim2]
    row[dim1] = cos_alpha * x - sin_alpha * y
    row[dim2] = sin_alpha * x + cos_alpha * y
    return row


def cartesian_to_spherical(x, y, z):
    r = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 3))

    if z == 0:
        phi = pi / 2
    else:
        phi = arctan(sqrt(pow(x, 2) + pow(y, 2)) / z)

    if x == 0:
        theta = 0
    else:
        theta = arctan(y / x)

    return r, phi, theta


def spherical_to_cartesian(r, phi, theta):
    x = r * sin(phi) * cos(theta)
    y = r * sin(phi) * sin(theta)
    z = r * cos(phi)

    return x, y, z


def spherical_rotate_to_cartesian(coord, phi_inc=0, theta_inc=0):
    r, phi, theta = coord
    return spherical_to_cartesian(r, phi + phi_inc, theta + theta_inc)

以上是关于python rotate_func.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python