加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pl3d.py 4.28 KB
一键复制 编辑 原始数据 按行查看 历史
Yuncheng-Xie 提交于 2023-10-12 16:33 . edited
import numpy as np
from numpy.linalg import norm
import matplotlib.pyplot as plt
from numpy import sin,cos
import tkinter as tk
# from PIL import Image, ImageTk
from scipy.interpolate.interpnd import LinearNDInterpolator
class ImageHolder:
def __init__(self):
self.img1 = None
# 创建类实例
image_holder = ImageHolder()
def mesh(b,a,n):
x=np.linspace(b,a,n)
y=np.linspace(b,a,n)
p=np.array([[np.array([x[i],y[j],0]) for i in range(x.shape[0])] for j in range(x.shape[0]) ])
n=p.shape[1]
pp=p.reshape([n*n,3])
return(pp)
# 定义旋转函数
def rotate_points_to_normal(points, normal):
# 步骤1:计算法向量的单位向量
normal_unit = normal / np.linalg.norm(normal)
if normal_unit[0]>0:
normal_unit=-normal_unit
# 步骤2:计算旋转轴
z_axis = np.array([0, 0, 1])
theta1 = np.arctan(normal_unit[1]/normal_unit[0])
theta2 = -np.arccos(normal_unit[2]/norm(normal_unit))
# 步骤4:创建旋转矩阵
c = np.cos(theta1)
s = np.sin(theta1)
tr1= np.array([
[c,s,0],[-s,c,0],[0,0,1]
])
s=np.sin(theta2)
c = np.cos(theta2)
tr2=np.array([
[c,0,-s],[0,1,0],[s,0,c]
])
tr=tr2@tr1
# 步骤5:应用旋转矩阵到点集
rotated_points = np.dot(points, tr) # 使用转置矩阵来进行点的旋转
# normal_unit = normal / np.linalg.norm(normal)
# if normal_unit[0]>0:
# normal_unit=-normal_unit
# # 步骤2:计算旋转轴
# z_axis = np.array([0, 0, 1])
# theta1 =np.pi/2- np.arctan(normal_unit[1]/normal_unit[0])
# theta2 = -np.arccos(normal_unit[2]/norm(normal_unit))
# # 步骤4:创建旋转矩阵
# c = np.cos(theta1)
# s = np.sin(theta1)
# tr1= np.array([
# [c,s,0],[-s,c,0],[0,0,1]
# ])
# s=np.sin(theta2)
# c = np.cos(theta2)
# tr2=np.array([
# [1,0,0],[0,c,s],[0,-s,c]
# ])
# tr=tr2@tr1
# # 步骤5:应用旋转矩阵到点集
# rotated_points = np.dot(points, tr) # 使用转置矩阵来进行点的旋转
return rotated_points
def trans(m,n,r=np.array([0,0,0])):
return(rotate_points_to_normal(m,n)+r)
def retrans(m,normal,r=np.array([0,0,0])):
points=m-r
# 步骤1:计算法向量的单位向量
normal_unit = normal / np.linalg.norm(normal)
if normal_unit[0]>0:
normal_unit=-normal_unit
# 步骤2:计算旋转轴
z_axis = np.array([0, 0, 1])
# 步骤3:计算旋转角度
theta1 = np.arctan(normal_unit[1]/normal_unit[0])
theta2 = -np.arccos(normal_unit[2]/norm(normal_unit))
# 步骤4:创建旋转矩阵
c = np.cos(theta1)
s = np.sin(theta1)
tr1= np.array([
[c,s,0],[-s,c,0],[0,0,1]
])
s=np.sin(theta2)
c = np.cos(theta2)
tr2=np.array([
[c,0,-s],[0,1,0],[s,0,c]
])
tr=tr2@tr1
# 步骤5:应用旋转矩阵到点集
rotated_points = np.dot(points,tr.T) # 使用转置矩阵来进行点的旋转
return rotated_points
def egg(s):
global img
if s=="夏轩哲nb":
tk.messagebox.showinfo("确实nb!","确实nb!")
return(0)
elif s=="谢昀城nb":
tk.messagebox.showinfo("确实nb!","确实nb!")
return(0)
elif s=="谢昀城":
tk.messagebox.showinfo("来自作者的彩蛋()","来自作者的彩蛋()")
return(0)
elif "原神" in s:
tk.messagebox.showinfo("启动!","启动!")
return(0)
elif "崩坏三" in s:
tk.messagebox.showinfo("为世界上所有美好而战!","为世界上所有美好而战!")
return(0)
elif "爱莉希雅" in s:
tk.messagebox.showinfo("爱门!","爱门!")
# wd2=tk.Tk()
# image_path = r"C:\Users\xyc\Desktop\光学荣誉\1.jpg"
# image_holder.img1 = Image.open(image_path)
# image_holder.img1 = ImageTk.PhotoImage(image_holder.img1)
# # 创建Label并插入图片
# image_label = tk.Label(wd2, image= image_holder.img1)
# image_label.pack()
return(0)
elif "星穹铁道" in s:
tk.messagebox.showinfo("愿此行终抵群星!","愿此行终抵群星!")
return(0)
else:
return 1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化