爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11448|回复: 9

[源代码] 一个python做的3d显示程序

[复制链接]

新浪微博达人勋

发表于 2014-7-3 22:27:39 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
# -*- coding: cp936 -*-
from visual import *
import serial
import string
import math
import thread
from time import time
import time
grad2rad = 3.141592/180.0
ser_buffer=[]

# Main scene
scene=display(title="AHRS",background=(0.8,0.8,1))
scene.range=(12,12,12)
#scene.forward = (0,-1,-0.25)
scene.forward = (1,0,-0.25)#观察角度
scene.up=(0,0,1)#场景方向

# Second scene (Roll, Pitch, Yaw)
scene2 = display(title='AHRS',x=0, y=0, width=500, height=200,center=(0,0,0), background=(0.8,0.8,1))#背景
scene2.range=(1,1,1)
scene.width=500
scene.y=200

scene2.select()
#Roll, Pitch, Yaw
cil_roll = cylinder(pos=(-0.4,0,0),axis=(0.2,0,0),radius=0.01,color=color.red)
cil_roll2 = cylinder(pos=(-0.4,0,0),axis=(-0.2,0,0),radius=0.01,color=color.red)
cil_pitch = cylinder(pos=(0.1,0,0),axis=(0.2,0,0),radius=0.01,color=color.blue)
cil_pitch2 = cylinder(pos=(0.1,0,0),axis=(-0.2,0,0),radius=0.01,color=color.blue)
#cil_course = cylinder(pos=(0.6,0,0),axis=(0.2,0,0),radius=0.01,color=color.blue)
#cil_course2 = cylinder(pos=(0.6,0,0),axis=(-0.2,0,0),radius=0.01,color=color.blue)
arrow_course = arrow(pos=(0.6,0,0),color=color.cyan,axis=(-0.2,0,0), shaftwidth=0.02, fixedwidth=1)


#Roll,Pitch,Yaw labels
label(pos=(-0.4,0.3,0),text="Roll",box=0,opacity=0,color=color.red)
label(pos=(0.1,0.3,0),text="Pitch",box=0,opacity=0,color=color.blue)
label(pos=(0.55,0.3,0),text="Yaw",box=0,opacity=0,color=color.black)
label(pos=(0.6,0.22,0),text="N",box=0,opacity=0,color=color.black)
label(pos=(0.6,-0.22,0),text="S",box=0,opacity=0,color=color.black)
label(pos=(0.38,0,0),text="W",box=0,opacity=0,color=color.black)
label(pos=(0.82,0,0),text="E",box=0,opacity=0,color=color.black)
label(pos=(0.75,0.15,0),height=7,text="NE",box=0,color=color.black)
label(pos=(0.45,0.15,0),height=7,text="NW",box=0,color=color.black)
label(pos=(0.75,-0.15,0),height=7,text="SE",box=0,color=color.black)
label(pos=(0.45,-0.15,0),height=7,text="SW",box=0,color=color.black)

L1 = label(pos=(-0.4,0.22,0),text="-",box=0,opacity=0,color=color.red)
L2 = label(pos=(0.1,0.22,0),text="-",box=0,opacity=0,color=color.blue)
L3 = label(pos=(0.7,0.3,0),text="-",box=0,opacity=0,color=color.black)

# Main scene objects
scene.select()
# Reference axis (x,y,z)
arrow(color=color.green,axis=(1,0,0), shaftwidth=0.02, fixedwidth=1)
arrow(color=color.green,axis=(0,1,0), shaftwidth=0.02 , fixedwidth=1)
arrow(color=color.green,axis=(0,0,-1), shaftwidth=0.02, fixedwidth=1)

label(pos=(0,0,0.8),text="AHRS",box=0,opacity=0)
label(pos=(1,0,0),text="X",box=0,opacity=0)
label(pos=(0,1,0),text="Y",box=0,opacity=0)
label(pos=(0,0,-1),text="Z",box=0,opacity=0)




#body parts
joint_0=sphere(pos=(0,0,0),radius=0.2, color=color.red)
joint_1=sphere(pos=(0,0,1),radius=0.2, color=color.red)
joint_2=sphere(pos=(0,0,2),radius=0.2, color=color.red)
joint_3=sphere(pos=(0,0,3),radius=0.2, color=color.red)
joint_4=sphere(pos=(0,0,4),radius=0.8, color=color.red)
joint_5=sphere(pos=(0,-2,3),radius=0.2, color=color.red)
joint_6=sphere(pos=(0,-2,1),radius=0.2, color=color.red)
joint_7=sphere(pos=(0,-2,-1),radius=0.2, color=color.red)
joint_8=sphere(pos=(0,2,3),radius=0.2, color=color.red)
joint_9=sphere(pos=(0,2,1),radius=0.2, color=color.red)
joint_10=sphere(pos=(0,2,-1),radius=0.2, color=color.red)
joint_11=sphere(pos=(0,-1,0),radius=0.2, color=color.red)
joint_12=sphere(pos=(0,-1,-3),radius=0.2, color=color.red)
joint_13=sphere(pos=(0,-1,-6),radius=0.2, color=color.red)
joint_14=sphere(pos=(0,1,0),radius=0.2, color=color.red)
joint_15=sphere(pos=(0,1,-3),radius=0.2, color=color.red)
joint_16=sphere(pos=(0,1,-6),radius=0.2, color=color.red)

bone_01=cylinder(pos=(0,0,0), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_12=cylinder(pos=(0,0,1), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_23=cylinder(pos=(0,0,2), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_34=cylinder(pos=(0,0,3), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_35=cylinder(pos=(0,0,3), axis=(0,-1,0), radius=0.1, length=2, color=color.cyan)
bone_38=cylinder(pos=(0,0,3), axis=(0,1,0), radius=0.1, length=2, color=color.cyan)
bone_56=cylinder(pos=(0,-2,3), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_67=cylinder(pos=(0,-2,1), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_89=cylinder(pos=(0,2,3), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_910=cylinder(pos=(0,2,1), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_011=cylinder(pos=(0,0,0), axis=(0,-1,0), radius=0.1, length=1, color=color.cyan)
bone_014=cylinder(pos=(0,0,0), axis=(0,1,0), radius=0.1, length=1, color=color.cyan)
bone_1112=cylinder(pos=(0,-1,0), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
bone_1213=cylinder(pos=(0,-1,-3), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
bone_1415=cylinder(pos=(0,1,0), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
bone_1516=cylinder(pos=(0,1,-3), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)




roll=0
pitch=0
yaw=0
while 1:
    words=hex_angle()
    if len(words)>2:
        yaw=words[0]*grad2rad
        pitch=words[1]*grad2rad
        roll=words[2]*grad2rad
    left_arm.axis=(cos(pitch)*cos(yaw),-cos(pitch)*sin(yaw),sin(pitch))
    left_arm.up=(sin(roll)*sin(yaw)+cos(roll)*sin(pitch)*cos(yaw),sin(roll)*cos(yaw)-cos(roll)*sin(pitch)*sin(yaw),-cos(roll)*cos(pitch))
   
    cil_roll.axis=(0.2*cos(roll),0.2*sin(roll),0)
    cil_roll2.axis=(-0.2*cos(roll),-0.2*sin(roll),0)
    cil_pitch.axis=(0.2*cos(pitch),0.2*sin(pitch),0)
    cil_pitch2.axis=(-0.2*cos(pitch),-0.2*sin(pitch),0)
    arrow_course.axis=(0.2*sin(yaw),0.2*cos(yaw),0)
    L1.text = str(float(roll/grad2rad ))
    L2.text = str(float(pitch/grad2rad ))
    L3.text = str(float(yaw/grad2rad ))
ser.close()


密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-7-3 23:28:30 | 显示全部楼层
给个效果展示图啊。
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

新浪微博达人勋

发表于 2014-7-4 09:11:20 | 显示全部楼层
我去,哪里copy了个代码黏着, 我还实验了一把,结果,可想而知,机器人
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-7-4 20:05:56 | 显示全部楼层
没有这个模块啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-7-8 17:41:05 | 显示全部楼层
厉害,收藏了大神。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-22 15:48:49 | 显示全部楼层
谢谢楼主分享啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-28 09:43:26 | 显示全部楼层
楼主高大上啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-11-11 21:30:09 | 显示全部楼层
学习。。。。。。
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2015-11-23 09:51:56 | 显示全部楼层
给个效果展示图啊。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-25 21:23:31 | 显示全部楼层
楼主能给个效果展示图不?
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表