I have a 3d point on a sphere and want to convert from that, to a UV point on the sphere's texture.
Could someone point in the right direction for the please? I can take a pure math solution.
Edit:
I currently have this, which does not return the correct UV coordinate. p is the 3d point on the sphere mesh.position is the position of the sphere
var x = (p.x-mesh.position.x)/500;
var y = (p.y-mesh.position.y)/500;
var z = (p.z-mesh.position.z)/500;
var u = Math.atan2(x, z) / (2 * Math.PI) + 0.5;
var v = Math.asin(y) / Math.PI + .5;
I have a 3d point on a sphere and want to convert from that, to a UV point on the sphere's texture.
Could someone point in the right direction for the please? I can take a pure math solution.
Edit:
I currently have this, which does not return the correct UV coordinate. p is the 3d point on the sphere mesh.position is the position of the sphere
var x = (p.x-mesh.position.x)/500;
var y = (p.y-mesh.position.y)/500;
var z = (p.z-mesh.position.z)/500;
var u = Math.atan2(x, z) / (2 * Math.PI) + 0.5;
var v = Math.asin(y) / Math.PI + .5;
Share
Improve this question
edited Oct 15, 2013 at 9:48
gibo
asked Oct 14, 2013 at 9:34
gibogibo
5372 gold badges5 silver badges22 bronze badges
4
- Its not possible to tell it really depends on how the sphere is mapped. I mean cartographers have spent a few centuries of fighting with this problem and its still not problem free. So each solution depends on how you want the map to wrap around and what error you want to minimize. – joojaa Commented Oct 14, 2013 at 10:57
-
1
In three.js
SphereGeometry.js
you will see the mapping from UV to XYZ. You need to invert that mapping. – WestLangley Commented Oct 14, 2013 at 16:14 - Did you read my answer? You need to transform uv-coordinate to pixel coordinate. 0,1 I've is the corner of the image. I think this give you u/width and v/height pixel coordinate. – Cybercartel Commented Oct 15, 2013 at 12:32
- I did, that's what I've based my working off.. To get the x y coordinate, I did this: x = u * texturewidth; – gibo Commented Oct 15, 2013 at 13:35
2 Answers
Reset to default 2The Wikipedia about uv-mapping is correct however you need to pute the uv coordinate for each vertex of the mesh. Then you need to transform the uv coordinate to pixel coordinate: Perfect (3D) texture mapping in opengl. Here is an other example: http://www.cse.msu.edu/~cse872/tutorial4.html. You can also try three.js. You also need to physically copy the uv triangle.
I found this wiki article - http://en.wikipedia/wiki/UV_mapping - they seem to use a sphere as their example.
Hope it helps.