# UV-ing a sphere procedurally

 0 So, I am trying to learn more about how to UV something procedurally. The first toy problem I'm trying to solve is how do you UV the default UV on the default Unity sphere. From left to right - default, planar, and Wikipedia spherical ``` for(var i=0;i

 0 It's more like something in the line of: ``````uvs[i] = Vector2(Mathf.Atan2(vertices[i].z,vertices[i].x)/Mathf.Pi/2,Mathf.Acos(vertices[i].y/r)/Mathf.Pi); `````` more ▼ answered May 29 '11 at 12:07 AM Wolfram 9k ● 8 ● 20 ● 52 why? and why are things scaled by pi by 2? May 29 '11 at 02:25 AM ina If you cut the sphere anywhere horizontally (=the X-Z-plane, if Y is up), you will get a circle. The position, or more precisely, the angle of a point on that circle is determined by the x and z coordinates. To compute this "longitude" for a given point on that circle, you can use the http://en.wikipedia.org/wiki/Atan2 function. However, since it returns a value in radians, where 2*Pi is a full circle, you need to divide by 2*Pi to map to the 0..1 range.Similarly, for the height, you can compute the "latitude" angle using the ratio height:radius, so that the "north pole" results in acos(1/1)=0, and the "south pole" in acos(-1/1)=Pi - again, the angle is in radians, so here divide by Pi (since we only have a half circle) to map to the 0..1 range. More intuitively, real latitude ranges from asin(1)=Pi/2 (=90 deg) to asin(-1)=-Pi/2 (=-90 deg). May 29 '11 at 02:53 AM Wolfram add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1353
x298
x236
x197
x138

asked: May 28 '11 at 11:47 PM

Seen: 1928 times

Last Updated: Dec 17 '11 at 10:58 PM