This is more of a blog entry, mostly a note to myself.

I wanted to generate a list of points on the surface of a deformed sphere. It turns out that Robert recently showed how to do that on a unit sphere.

http://www.mapleprimes.com/questions/35962-Limited-Random-Points-Plot-On-A-Surface#comment66936

Adapting his code is straightforward. So here is what I came up with. One proc generates the random points on the surface of the ellipsoid. Another proc generates a plot of the surface of the ellipsoid in order to visualize the points on the surface.

For some reason I opted for spherical coordinates. I ran into problems generating uniformly spaced points. Eventually I read this note (thanks Alec for the pointer), and certain things became clearer.

http://mathworld.wolfram.com/SpherePointPicking.html

If anyone looks at this and sees errors, please do point them out.

NumberOfPoints := 1000:
ScalingParameter := 10: # Scales the 3 axes in the same proportions
DistortionParameters := [0.5,1,1.5]: # Re-scales the 3 axes differently to deform the sphere

RandomPointsOnEllipsoidProc := proc(n::posint,d::positive,r::list)
  local X,Y,Z,rX,rY,rZ,U,V;
  description "The first argument n is the number of points. The second argument d is the scaling parameter (diameter) of the sphere. The third argument r is a list of the distortion parameters";
  rX,rY,rZ := seq( r[i], i = 1 .. 3):
  U := Statistics:-Sample( Uniform(-1,1), n) :
  V := Statistics:-Sample( Uniform(0,2*Pi), n) :
  < seq( d * <rX*sqrt(1-U[i]^2)*cos(V[i]) | rY*sqrt(1-U[i]^2)*sin(V[i]) | rZ*U[i] >, i = 1 .. n) > ;
end proc:


PlotOfEllipsoidProc := proc(d::positive,r::list)
  local X,Y,Z,rX,rY,rZ,u,v,p;
  description "The first argument d is the scaling parameter (diameter) of the sphere. The second argument r is a list of the distortion parameters.";
  rX,rY,rZ := seq( r[i], i = 1 .. 3):
  X,Y,Z :=  rX*sqrt(1-u^2)*cos(v), rY*sqrt(1-u^2)*sin(v), rZ*u:
  p := plot3d( d * [X,Y,Z] , u = -1 .. 1, v = 0 .. 2*evalf(Pi)): # evalf(Pi) prevents automatic use of Pi in labels
  plots:-display(p);
end proc:

RandomPointsOnEllipsoid := RandomPointsOnEllipsoidProc(NumberOfPoints,ScalingParameter,DistortionParameters):
PlotOfRandomPointsOnEllipsoid := plots:-pointplot3d(RandomPointsOnEllipsoid, 'symbol' = solidsphere, 'symbolsize' = 8):
PlotOfRandomPointsOnEllipsoidRed :=

plots:-display( PlotOfRandomPointsOnEllipsoid
  , 'axes' = box=
  , 'color ' = red
):
plots:-display(%);

PlotOfEllipsoid := PlotOfEllipsoidProc(ScalingParameter,DistortionParameters):
PlotOfEllipsoidBlue :=
plots:-display( PlotOfEllipsoid
  , 'axes' = box
  , 'style' = patchnogrid
  , 'color ' = blue
):
plots:-display(%);

plots:-display( [ PlotOfRandomPointsOnEllipsoidRed, PlotOfEllipsoidBlue]
  , 'axes' = none
  , 'scaling' = constrained
  , 'orientation' = [-45,45]
);



Please Wait...