Distortion in spherical coordinates

495 Views Asked by At

I'm trying to realized 3d models of stones. My idea was to create a 2D random angular distribution with opportune correlation, namely

enter image description here

$R(\theta,\varphi)=rand(\theta,\varphi,c_l)$

where $\theta\in[-\pi,\pi], \varphi\in[-\pi/2,\pi/2]$.

Once the surface is generated, I convert it to a 3D cartesian surface computing for every point of my domain $\mathbf{x}=(x,y,z)$ the following standard conversion

$\begin{cases}x=rcos(\theta)cos(\varphi)\\y=rsin(\theta)cos(\varphi)\\z=rsin(\varphi)\\\end{cases}$

$\theta^*=atan(y/x)$

$\varphi^*=atan(z/\sqrt{x^2+y^2})$

$r=\sqrt{(x^2+y^2+z^2)}$

The condition to determine if the point lies inside the rock is trivially

$r<R(\theta^*,\varphi^*)\implies\mathbf{x}\in\text{ sphere}$

This is the result I get:

enter image description here

As you can see in proximity of the z axis (red) there is some kind of distortion coming from the spherical to cartesian transformation. Is there any way to reduce it?

1

There are 1 best solutions below

1
On BEST ANSWER

Your approach is inherently dependent on the coordinate system. I guess I'd try to find some approach which is invariant under changes of the coordinate system. For that I'd first have a look at the related topic of sphere point picking.

For example, you could use that to place a number of bups on the sphere, each with a random weight. So for $1\le i\le n$ you'd choose $-1<z_i<1, -\pi<\theta_i<\pi, -1<w_i<1$ uniformly and independently, and then turn that into $x_i=\sqrt{1-z_i^2}\cos\theta_i, y_i=\sqrt{1-z_i^2}\sin\theta_i$. Then for every point on $(x,y,z)$ the sphere, you could do something like this:

$$R(x,y,z)=C+\frac{1}{n\sqrt{x^2+y^2+z^2}}\sum_{i=1}^n\max(0, xx_i+yy_i+zz_i)w_i$$

The idea is that the closer one of these $n$ bumps is to a given direction, the stronger it influences the radius in that direction. Only half the sphere will be considered for this (i.e. you ignore negative dot products), which avoids too strong a correlation between antipodal points. There are a number of parameters to tune. You might want to adjust the offset $C$, and you also might want to adjust the distribution for these $w_i$. You might tune the number $n$, and so on. I haven't tried and of this, and I'm not sure that it will actually look stone-like. I am however certain that its appearance will be independent of the choice of coordinate system, and I simply hope that the rest works out as well.

If you try this approach, feel free to edit my answer and provide some images.