Professional Documents
Culture Documents
3D Graphics Tutorial: There Is A Reason To Learn Trigonometry
3D Graphics Tutorial: There Is A Reason To Learn Trigonometry
3D graphics tutorial
Rotating objects
Home
About
Introduction Rotating things in three dimensions sounds complicated and it My sister's handmade cards on
Etsy.
Creating 3D objects can be, but there are some simple rotations. For example, if
Mendeley Web Importer
Drawing 3D objects we imagine rotating our cube around the z-axis (which points
Rotating 3D objects out of the screen), we are actually just rotating a square in Easily save references with jus one click
Generating 3D objects two dimensions.
Signinin
Sign
x' = x × cos(θ)
y' = x × sin(θ)
Rotating a point (x, 0) around the
If you don't understand where these equations came from, origin by θ.
x = r × cos(α)
y = r × sin(α)
This function loops through all the nodes in the node array,
finds its current x and y coordinates and then updates them.
We find sin(theta) and cos(theta) outside the loop so we only
need to calculate it once.
We can test the function by calling it. Try rotating the cube by
30 degrees.
rotateZ3D(30);
Our cube is slightly more
interesting, but not much.
You can see the complete code here.
rotateX3D(30);
rotateY3D(30);
You can see the complete code here. Try using the slider to
change the values in the function calls.
User interaction
We can rotate the cube by adding function calls, but it's a lot
more useful (and satisfying) if we can rotate it using the
mouse. For this we need to create a mouseDragged()
function. This function is automatically called whenever the
mouse is dragged.