Ejemplo n.º 1
0
from browser import WindowAnimationRunner, document
from geometry import CartesianSpace, ArrowBuilder, ProbeBuilderE3
from workbench import Workbench
from e3ga import *
from math import exp, sqrt, pi

i = VectorE3(1, 0, 0)
j = VectorE3(0, 1, 0)
k = VectorE3(0, 0, 1)

f = 3 * i - 2 * j
g = 2 * j
h = i + j

scene = CartesianSpace()

probeR = ProbeBuilderE3().color("red").build()
scene.add(probeR.grade1)

probeG = ProbeBuilderE3().color("green").build()
scene.add(probeG.grade1)

probeB = ProbeBuilderE3().color("blue").build()
scene.add(probeB.grade1)

probeY = ProbeBuilderE3().color("yellow").build()
scene.add(probeY.grade1)

probeC = ProbeBuilderE3().color("cyan").build()
scene.add(probeC.grade1)
Ejemplo n.º 2
0
'''
This lesson demonstrates adding a keyboard handler.
We respond to the Escape key in order to end the animation prematurely.
'''
from browser import document, WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from math import cos, sin, pi
from workbench import Workbench3D

T = 5
omega = 2 * pi / T
R = 4

space = CartesianSpace()

sphere = SphereBuilder().color(0x0000FF).radius(0.2).build()
space.add(sphere)

workbench = Workbench3D(space.renderer.domElement, space.renderer,
                        space.camera)

timeOut = 10


def tick(t):
    sphere.position.set(R * cos(omega * t), R * sin(omega * t), 0)
    space.render()


def terminate(time):
    # The animation ends when the time is greater than the timeOut.
Ejemplo n.º 3
0
'''
This lesson demonstrates adding a keyboard handler.
We respond to the Escape key in order to end the animation prematurely.
'''
from browser import document, WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from math import cos, sin, pi
from workbench import Workbench3D

T = 5
omega = 2 * pi / T
R = 4

space = CartesianSpace()

sphere = SphereBuilder().color(0x0000FF).radius(0.2).build()
space.add(sphere)

workbench = Workbench3D(space.renderer.domElement, space.renderer, space.camera)

timeOut = 10

def tick(t):
    sphere.position.set(R * cos(omega*t), R * sin(omega*t), 0)
    space.render()

def terminate(time):
    # The animation ends when the time is greater than the timeOut.
    # The animation may be ended prematurely by changing the timeOut value.
    done = time > timeOut
    return done
Ejemplo n.º 4
0
    return Euclidean(w, 0.0, 0.0)


f = Vector(1.0, 0.0)
g = Vector(3.0, 5.0)
k = Scalar(4.0)
h = k * f

print "f => " + str(f)
print "g => " + str(g)
print "k => " + str(k)

print "k * f => " + str(k * f)
print "4 * f => " + str(4.0 * f)

scene = CartesianSpace()


def magnitude(v):
    return sqrt(v.x * v.x + v.y * v.y)


def attitude(v):
    a = VectorE3(0, 0, 1)
    b = VectorE3(v.x, v.y, 0) / magnitude(v)
    numer = 1 + b * a
    denom = ScalarE3(sqrt(2 + (a % b)))
    R = numer / denom
    return R

Ejemplo n.º 5
0
def Scalar(w):
    return Euclidean(w, 0.0, 0.0)

f = Vector(1.0, 0.0)
g = Vector(3.0, 5.0)
k = Scalar(4.0)
h = k * f

print "f => " + str(f)
print "g => " + str(g)
print "k => " + str(k)

print "k * f => " + str(k * f)
print "4 * f => " + str(4.0 * f)

scene = CartesianSpace()

def magnitude(v):
    return sqrt(v.x * v.x + v.y * v.y)

def attitude(v):
    a = VectorE3(0, 0, 1)
    b = VectorE3(v.x, v.y, 0) / magnitude(v)
    numer = 1 + b * a
    denom = ScalarE3(sqrt(2 + (a % b)))
    R = numer / denom
    return R

arrowF = ArrowBuilder().scale( magnitude(f) ).attitude( attitude(f) ).color("red").build()
scene.add(arrowF)
arrowF.position.set(f.x / 2.0, f.y / 2.0, 0.0)
Ejemplo n.º 6
0
from browser import WindowAnimationRunner, document
from geometry import CartesianSpace, ArrowBuilder, ProbeBuilderE3
from workbench import Workbench
from e3ga import *
from math import exp, sqrt, pi

i = VectorE3(1, 0, 0)
j = VectorE3(0, 1, 0)
k = VectorE3(0, 0, 1)

f = 3 * i - 2 * j
g = 2 * j
h = i + j

scene = CartesianSpace()

probeR = ProbeBuilderE3().color("red").build()
scene.add(probeR.grade1)

probeG = ProbeBuilderE3().color("green").build()
scene.add(probeG.grade1)

probeB = ProbeBuilderE3().color("blue").build()
scene.add(probeB.grade1)

probeY = ProbeBuilderE3().color("yellow").build()
scene.add(probeY.grade1)

probeC = ProbeBuilderE3().color("cyan").build()
scene.add(probeC.grade1)
Ejemplo n.º 7
0
            parts.append("Scalar(" + str(self.w) + ")")
        if self.x != 0.0 or self.y != 0.0:
            parts.append("Vector(" + ", ".join([str(self.x), str(self.y)]) + ")")
        return "+".join(parts)

def Vector(x, y):
    return Euclidean(0.0, x, y)

def Scalar(w):
    return Euclidean(w, 0.0, 0.0)

f = Vector(1.0, 2.0)
g = Vector(4.0, -3.0)
k = Scalar(4.0)

scene = CartesianSpace()

def magnitude(v):
    return sqrt(v.x * v.x + v.y * v.y)

def attitude(v):
    a = VectorE3(0.0, 0.0, 1.0)
    b = VectorE3(v.x, v.y, 0.0) / sqrt(v.quadrance())
    numer = 1 + b * a
    denom = sqrt(2 + (a % b))
    R = numer / denom
    return R

arrowF = ArrowBuilder().name("f").scale( magnitude(f) ).attitude( attitude(f) ).color(0xFF0000).build()#.axis(f.x, f.y, 0).build()
scene.add(arrowF)
arrowF.position.set(f.x/2,f.y/2,0)
Ejemplo n.º 8
0
from browser import *
#rom three import *
from workbench import *
from geometry import CartesianSpace, VectorE3, SphereBuilder, ScalarE3, ProbeBuilderE3

timeOut = 60

space3D = CartesianSpace()
i = VectorE3(1.0, 0.0, 0.0)
j = VectorE3(0.0, 1.0, 0.0)
k = VectorE3(0.0, 0.0, 1.0)
I = i * j * k

workbench3D = Workbench3D(space3D.renderer.domElement, space3D.renderer,
                          space3D.camera)

particle = SphereBuilder().color("red").radius(0.1).build()
particle.charge = ScalarE3(1.0)
particle.mass = ScalarE3(1.0)
particle.position = VectorE3(0.0, 1.0, 0.0)
particle.velocity = VectorE3(0.0, -1.0, 0.0)
space3D.add(particle)

# Probe to show the velocity of the particle.
probeV = ProbeBuilderE3().color(particle.material.color.getHex()).build()
space3D.add(probeV.grade1)

# Probe to show the magnetic field at the particle position.
probeB = ProbeBuilderE3().color(0x0000FF).build()
space3D.add(probeB.grade1)
space3D.add(probeB.grade2)
Ejemplo n.º 9
0
'''
This lesson demonstrates adding a simple object to a scene.
'''
from browser import WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from workbench import Workbench3D

scene = CartesianSpace()

# The object is created using the builder pattern.
sphere = SphereBuilder().color(0x0000FF).build()
# Once created, the object must be added to the scene in order to be rendered.
scene.add(sphere)

workbench = Workbench3D(scene.renderer.domElement, scene.renderer,
                        scene.camera)


def tick(t):
    scene.render()


def terminate(t):
    done = t > 4
    return done


def setUp():
    workbench.setUp()

Ejemplo n.º 10
0
'''
This lesson demonstrates adding a simple object to a scene.
'''
from browser import WindowAnimationRunner
from geometry import CartesianSpace, SphereBuilder
from workbench import Workbench3D

scene = CartesianSpace()

# The object is created using the builder pattern.
sphere = SphereBuilder().color(0x0000FF).build()
# Once created, the object must be added to the scene in order to be rendered.
scene.add(sphere)

workbench = Workbench3D(scene.renderer.domElement, scene.renderer, scene.camera)

def tick(t):
    scene.render()

def terminate(t):
    done = t > 4
    return done

def setUp():
    workbench.setUp()

def tearDown(e):
    workbench.tearDown()
    if e:
        print e