大力推广建设电子商务网站技术,潍坊大型网站建设平台,广州番禺服装网站建设,服装品牌vi设计案例文章目录画个球让球转起来画个球
不管篮球和不和鸡联系起来#xff0c;都首先得有个球#xff0c;或者说要有一个球面#xff0c;用参数方程可以表示为 xrcosϕcosθyrcosϕsinθzrsinϕ\begin{aligned} x r\cos\phi\cos\theta\\ y r\cos\phi\sin\th…
文章目录画个球让球转起来画个球
不管篮球和不和鸡联系起来都首先得有个球或者说要有一个球面用参数方程可以表示为
xrcosϕcosθyrcosϕsinθzrsinϕ\begin{aligned} x r\cos\phi\cos\theta\\ y r\cos\phi\sin\theta\\ z r\sin\phi \end{aligned} xyzrcosϕcosθrcosϕsinθrsinϕ
当然有球还不行还得有篮球。篮球其实很好画只要在球上加两个背带就可以了这一点可以用Python来实现但考虑到方便还是用PS直接P了一下希望最后画出来不是太离谱。
那么现在球有了还必须得有鸡所以在百度上找一只。然后把这只鸡映射到球面上。 接下来就是关键步骤如何将这个平面卷成一个球方法也很简单只需进行颜色映射就行了。
import numpy as np
import matplotlib.pyplot as plt
path bracken1.jpg
img plt.imread(path)
#img img[::5, ::5, :]
h, w, c img.shape
ys, xs np.indices([h, w])
th xs/w*np.pi*2
phi np.pi/2 - ys/h*np.pix np.cos(phi)*np.cos(th)
y np.cos(phi)*np.sin(th)
z np.sin(phi)cs [tuple(c/255) for c in img.reshape(-1,3)]
ax plt.subplot(projection3d)
ax.scatter(x, y, z, marker., ccs)
plt.axis(off)
plt.show()效果为 让球转起来
当然需要注意的一个是这是个球而不是一个圆所以下面让这个球转一下。想要让球转动那就得有一个旋转矩阵三个方向的旋转矩阵如下表
Rx(θ)R_x(\theta)Rx(θ)Rx(θ)R_x(\theta)Rx(θ)Rx(θ)R_x(\theta)Rx(θ)[1000Cθ−Sθ0SθCθ]\begin{bmatrix}100\\0C_\theta-S_\theta\\0S_\thetaC_\theta\\\end{bmatrix}1000CθSθ0−SθCθ[Cθ0Sθ010−Sθ0Cθ]\begin{bmatrix}C_\theta0 S_\theta\\010\\-S_\theta0C_\theta\\\end{bmatrix}Cθ0−Sθ010Sθ0Cθ[CθSθ0−SθCθ0001]\begin{bmatrix}C_\theta S_\theta0\\-S_\thetaC_\theta0\\001\end{bmatrix}Cθ−Sθ0SθCθ0001
由于只需绕Z轴转动所以代码如下
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animationcos lambda th : np.cos(np.deg2rad(th))
sin lambda th : np.sin(np.deg2rad(th))Rz lambda th : np.array([[cos(th) , -sin(th), 0],[sin(th), cos(th), 0],[0 , 0, 1]])xyz np.array([x,y,z]).reshape(3,-1)fig plt.figure(figsize(5,5))
ax fig.add_subplot(projection3d)
ax.grid()lines ax.scatter(x, y, z, marker., ccs)def animate(n):# 按照xyz顺序旋转axis [2,1,0]shape xyz.shapelines._offsets3d Rz(n)xyzreturn lines,ani animation.FuncAnimation(fig, animate, range(0, 360, 2), interval25, blitTrue)#plt.show()
ani.save(zyx.gif)效果如下还挺有喜感的。