资源简介
实现了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试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论