I try to bend a plane mesh using spherical coordinates. I token formulas on wikipedia and it almost work ! But some vertices are positionned to the same place. The mesh plane is placed at 0,0,0, you can watch the result here :
Before : http://hpics.li/78c0871
After : http://hpics.li/19ada1a
And here is my code :
@radius = 4
@oPhi = 0
@oTheta = 0
projection : (vertice) ->
p = Math.sqrt(vertice.x ** 2 + vertice.y ** 2)
c = Math.asin(p/@radius)
phi = Math.asin(Math.cos(c) * Math.sin(@oPhi) + (vertice.y * Math.sin(c) * Math.cos(@oPhi) / p))
theta = @oTheta + Math.atan((vertice.x * Math.sin(c)) / (p * Math.cos(@oPhi) * Math.cos(c) - vertice.y * Math.sin(@oPhi) * Math.sin(c)))
vertice.x = @radius * Math.sin(phi) * Math.cos(theta)
vertice.z = @radius * Math.sin(phi) * Math.sin(theta)
vertice.y = @radius * Math.cos(phi)
Thanks for help !