Datasheet

16
Part 1: Getting Started
The parametric equations for a torus are:
x=(c+a*cos(v))cos(u)
y=(c+a*cos(v))sin(u)
z=a*sin(v)
where c is the donut radius, and a is the tube radius. And u is the parameter that takes you around the
larger radius (the donut) and v around the smaller tube radius as shown in Figure 1.7.
Z
tube
radius
a
V
u
C
donut radius
Figure 1-7
You now use these equations to create a parametric path on your torus. What you want to do is have
your graphical element spiral around the torus. You can accomplish this by iterating the parameters u
and v simultaneously adjusting v to get to the desired spiral velocity. The parametric path is extremely
easy to execute. Just take the code from the 3D Flash 10 Engine in 13 lines and substitute your parametric
equations for ball.x, ball.y, and ball.z as shown below:
import flash.display.Sprite;//imports sprite class
var myAngle:Number =0;//Angle of ball
var ball:Sprite = new Sprite();//instantiates ball sprite
ball.graphics.beginFill(0xFF0000);//Assign a ball color
ball.graphics.drawCircle(0, 0, 10);//draws your ball at 0,0
ball.graphics.endFill();//ends the fill
addChild(ball);//adds the ball to the stage
addEventListener(Event.ENTER_FRAME, myonEnterFrame);//loops equations
function myonEnterFrame(event:Event):void{
myAngle=myAngle+.1;//iterates angle
//ball parametric orbit x
ball.x = (100+50*Math.cos(2*myAngle))*Math.cos(myAngle/4)+200;
//ball parametric orbit y
ball.y = (100+50*Math.cos(2*myAngle))*Math.sin(myAngle/4)+200;
//ball parametric orbit z
ball.z = 50*Math.sin(2*myAngle);}
It works flawlessly, but a single ball isn t very exciting. Now add a few more balls to your
parametric path.
c01.indd 16c01.indd 16 12/14/09 3:03:28 PM12/14/09 3:03:28 PM