crossproduct.py :  » Game-2D-3D » Visual » visual-5.32_release » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » Visual 
Visual » visual 5.32_release » examples » crossproduct.py
from visual import *
# demonstration of vector cross product

print """
Vector cross product: Red cross Green = Yellow
Drag to change green vector
Click to toggle fixed angle or fixed length
"""

# Ruth Chabay

scene.title="Vector Cross Product"
scene.width=600
scene.height=600
R = 0.15*4
plane = curve(pos=[(0, -10, -10), (0, -10, 10), (0, 10,10), (0, 10, -10),
              (0, -10, -10), (0,-6,-10), (0,-6,10), (0, -2, 10), (0, -2, -10),
              (0,2,-10), (0,2,10), (0,6,10), (0,6,-10),(0,10, -10),              
              (0,10,-6), (0,-10,-6), (0,-10,-2), (0,10,-2), (0,10,2),
              (0,-10,2), (0,-10,6), (0,10,6)])

s_theta=sphere(pos=(0,-12,-10), radius=0.6, color=(0.6, 1.0, 0.6))
s_theta_label=label(pos=s_theta.pos, text="Fix Angle", yoffset=-5,
                    opacity=0, box=0, line=0)
s_length=sphere(pos=(0,-12,10), radius=0.6, color=(0.6, 0.6, 1.0))
s_length_label=label(pos=s_length.pos, text="Fix Length", yoffset=-5,
                    opacity=0, box=0, line=0)

s_text=label(pos=(0,12,0), text="Yellow = Red x Green",
                    opacity=0, box=0, line=0)
               
fixlength = 0
fixtheta = 0

avector = array ([0,0,-3.5])
bvector = vector (0,3,2)

a = arrow(pos=(0,0,0), shaftwidth=R, color=crayola.red)
b = arrow(pos=(0,0,0), axis=bvector, shaftwidth=R, color=crayola.green)
a.axis =avector
cvector = cross(avector,bvector)
c = arrow(pos=(0,0,0), axis=cvector, shaftwidth=R, color=crayola.yellow)

scene.autoscale = 0
scene.forward = (-1,-.5,-1)

drag = 0

while True:
    rate(100)
    if scene.mouse.events:
        m = scene.mouse.getevent()
        if m.drag:
            drag = True
            obs = None
        elif m.drop:
            drag = False
        elif m.click:
            if m.pick is s_length:
                if fixtheta:
                    fixtheta = not(fixtheta)
                    s_theta.color = (0.6, 1.0, 0.6)
                fixlength=not(fixlength)
                if fixlength:
                    s_length.color=(0.0, 0.0, 1.0)
                else:
                    s_length.color=(0.6, 0.6, 1.0)
            elif m.pick is s_theta:
                if fixlength:
                    fixlength = not(fixlength)
                    s_length.color=(0.6, 0.6, 1.0)
                fixtheta = not(fixtheta)
                if fixtheta:
                    s_theta.color=(0.0, 1.0, 0.0)
                else:
                    s_theta.color = (0.6, 1.0, 0.6)
    if drag:
        rate(100)
        newobs=scene.mouse.project(normal=vector(1,0,0), d=0)
        if newobs and (newobs != obs):
            obs = newobs
            if not fixlength and not fixtheta:
                bvector = obs
                if bvector.mag > 20: bvector=bvector*(20/bvector.mag)
                b.axis=bvector
            elif fixlength:
                length=3.9
                bvector = length*norm(obs)
                b.axis=bvector
            elif fixtheta:
                length=mag(obs)
                bvector=length*norm(vector(0, .3, 1))
                b.axis=bvector

            cvector=cross(avector,b.axis)
            c.axis=cvector

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.