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
''' 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.
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)