1

I'm trying to generate a mesh from a sphere of radius r. My goal is to create a UV sphere such that every point on the polyhedron has distance from the sphere smaller than tol.

The following code creates a grid of points on the sphere. How can I compute parallels_count and meridians_count so that all the point of the mesh are within tolerance?

  for j in parallels_count:
     parallel = PI * (j+1) / parallels_count
  for i in meridians_count:
     meridian = 2.0 * PI * i / meridians_count
  return spherical_to_cartesian(meridian, parallel)

The code comes from here, and this is a picture of the UV sphere:

this

The distance between each face of the mesh and the sphere will be maximum around the center of the face. So, for the distance between a face and the sphere to be smaller than tol it is not sufficient that the distances between the edges of the face and the corresponding circumferences are smaller than tol. This picture is out of context but helps me explaining what I mean.

enter image description here

sgiulia
  • 31
  • 4
  • Hello why don't you use the parametric equation of a sphere which is `x = r*cos(u)*cos(v) ` with `-PI <= u <= PI ; -PI/2 <= v <= PI/2` and `y = r*sin(u)*cos(v)` and `z=r*cos(v)` ? – Franck Ngako Nov 15 '16 at 14:57
  • Hi, I think that's what the method `spherical_to_cartesian()` does. `parallel` and `meridian` are like your `u` and `v`. – sgiulia Nov 15 '16 at 15:28

1 Answers1

1

the biggest distance between points is on equator so use circle circumference to obtain angular step if I am not mistaken it should be...

dangle = tol/r; //[rad]

where r is sphere radius in the same units as tol you can use smaller step to be sure like dangle*=0.75; use this for both parallel and meridian angles.

If you want your counts instead then try:

meridians_count = (2.0*PI*r/tol)+1; // ceil or +1 just to be sure
parallels_count = 0.5*meridians_count;

It is still early here so I hope I did not make any silly math mistake (the easiest stuff is the worst for silly bugs).

Also take a look at few related QA's of mine:

[Edit1] well your new definition of tol changes everything

I see it like this:

tol

sin(da/2) = (r-tol)/r
da = 2.0*asin((r-tol)/r)

If you convert to sphericalsurface than max difference is in center of uv grid cell which represents sqrt(2)*dadiagonal so try to use:

da = sqrt(2.0)*asin((r-tol)/r)

so your angle step should be a bit smaller than that ...

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thanks @Spektre, but dividing the equator's length by `tol` you get `meridians_count` arcs of length equal to `tol`. I can't find a 3D picture, but referring to [this](http://arcmaster.ca/working-with-arcs/determine-rise/) 2D picture, you are getting an "arc length" of `tol` while I'm looking for the 3D equivalent of "rise" to be of length <`tol`. – sgiulia Nov 16 '16 at 10:15
  • Hi @Spektre, thank you again! I modified the question hoping that it makes the definition of `tol` clearer. Applying the 2D approach both on the U and V directions, the mesh might not be within tolerance in the center of some quadrilateral faces. – sgiulia Nov 17 '16 at 16:02
  • @sgiulia I mean use for sphere `da <= sqrt(2.0)*asin((r-tol)/r)` – Spektre Nov 18 '16 at 07:35