# Raytracing: Texture mapping of primitives

## Recommended Posts

Can someone help me on the equations of texture coordinates for sphere, cylinder, cone and cube? Thanks in advance

##### Share on other sites
atcdevil    145
this is something you could find in 2 seconds using google you know...

disclaimer, this could be wrong, but I hope this helps

for the sphere:
x=ro*cos(theta)*sin(phi)
y=ro*sin(theta)*sin(phi)
z=ro*cos(phi)
0<=theta<=2PI
0<=phi<=PI
you'll leave ro as a constant (it's the radius), and theta and phi can correspond to texture coordinates

for the cylinder:
x=r*cos(theta)
y=r*sin(theta)
z=z
0<=theta<=2PI
0<=z<= whatever height you want
r is constant.. it's the radius
And z and theta will correspond to texture coordinates.

I'm guessing the cone is the same as the cylinder except:
x=z*r*cos(theta)
y=z*r*sin(theta)

and a cube.. I have no clue how to parameterize.

Eelco    301

##### Share on other sites
Dmytry    1151
again, there's no such single thing as correct texture coordinates on primitive.

You can use any texture coordinates you like, and that's all. For texturing with 2D tecture map, you should make function that takes 3D position on surface of object and output 2D texture coordinate that makes sense. For sphere, you can use cubemap for texturing, or you
can use polar coords, etc. For cube you can use cubemap, but also you can use polar coords. For cone you can use "unfolded" cone, like paper shape that can be folded into cone. For torus you can use parametric equation of torus. And you can use cubemap. Or instead of point you can use surface normal together with cubemap. Possibilities is endless.

##### Share on other sites
dimensionX    100
Check out the book 'Introduction to Raytracing" - Andrew Glassner

It has a detailed explanation and mathematics behind texture mapping sphere, quad, triangle, cone, cylinder and even quadrics. I am sure you will find it very help full.

Cheers!