资源简介
实现了3D方块动画旋转,自己也可以输出角度来控制。
代码片段和文件信息
import math
import matplotlib.pyplot as plt
import matplotlib.animation as animation
class Point3D:
def __init__(self x = 0 y = 0 z = 0):
self.x self.y self.z = x y z
def rotateX(self angle):
“““ Rotates this point around the X axis the given number of degrees. “““
rad = angle * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
y = self.y * cosa - self.z * sina
z = self.y * sina + self.z * cosa
return Point3D(self.x y z)
def rotateY(self angle):
“““ Rotates this point around the Y axis the given number of degrees. “““
rad = angle * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
z = self.z * cosa - self.x * sina
x = self.z * sina + self.x * cosa
return Point3D(x self.y z)
def rotateZ(self angle):
“““ Rotates this point around the Z axis the given number of degrees. “““
rad = angle * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
x = self.x * cosa - self.y * sina
y = self.x * sina + self.y * cosa
return Point3D(x y self.z)
def project(self win_width win_height fov viewer_distance):
“““ Transforms this 3D point to 2D using a perspective projection. “““
factor = fov / (viewer_distance + self.z)
x = self.x * factor + win_width / 2
y = -self.y * factor + win_height / 2
return Point3D(x y self.z)
class Simulation:
def __init__(
self
width=128
height=160
fov=64
distance=4
rotateX=5
rotateY=5
rotateZ=5
):
self.vertices = [
Point3D(-11-1)
Point3D(11-1)
Point3D(1-1-1)
Point3D(-1-1-1)
Point3D(-111)
Point3D(111)
Point3D(1-11)
Point3D(-1-11)
]
# Define the edges the numbers are indices to the vertices above.
self.edges = [
# Back
(0 1)
(1 2)
(2 3)
(3 0)
# Front
(5 4)
(4 7)
(7 6)
(6 5)
# Front-to-back
(0 4)
(1 5)
(2 6)
(3 7)
相关资源
- 传智播客 python基础班 + 就业班 + 课件
- 基于PYTHON+OPENCV的SIFT SURF图像特征匹配
- python总结
- boost.python 动态编译库
- 高斯投影正反算Python源码
- python xlutils
- Python3网络爬虫实战思维导图
- ros_arduino_python 调通版
- 数据挖掘十大算法源代码Python)
- XModem -发送端源代码Python语言实现
- pytracking/pytracking/evaluation/tracker.py
- Python爬取教务系统课程表
- 元胞自动机模拟交通道路_Python
- Python二级考试试题.zip
- python实现扫描线填充算法,可以画凹
- python3 包装的httpclient,支持session
- python日期时间运算
- python实现的ping工具
- Python简版聊天室代码
- Flask-login
- 矩阵分解在MovieLens上的Python实现
- 全国840个气象站点日照时数转日总太
- python 3.6 socket传输视频
- 基于PYQT编写的人脸识别软件
- 续Python3.x+PyQtChart实现数据可视化界面
- 疯狂Python讲义习题答案.rar
- A*算法解决十五数码问题Python程序、报
- 使用python tkinter写的登陆窗口源码
- caffe_pb2.py
- LUTAI.Tools.IronPythonCheckTool
评论
共有 条评论