# Parametric Equation to Point Cloud, How To?

This topic is 4336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, How do you go about building a point cloud from a parametric equation? What I want to do is to create a function like the following: Sphere(Radius, Levels, Slices); and this function will generate a uniformally distributed point cloud depicting a sphere of the given radius composed of the given number of slices and the given number of levels. If you have ever used any rendering software, like Blender, then you've probably seen something like this. I have to program this on my own now, and I've been given a whole list of parametric equations: Sphere, Ellipsoid, Cylinder, Double Sheet Elliptic Hyperboloid, etc... It's just been WAY too long since I had (or used) the math skills needed to write this function. I figure, if someone can help me with the sphere, I can apply the ideas to the other shapes. So, how to I change this: x = sqrt(r^2-u^2)cos(theta) y = sqrt(r^2-u^2)sin(theta) z = u into this: Sphere(Radius, Levels, Slices); Obviously, I realize it will involve some nested loops, and a lot of pi. But, past that, I'm really not sure how to approach this. I feel kind-of dumb asking, I really should know this...can anyone help me? Thanks, have a great day! -Langecrew-

##### Share on other sites
Quote:
 Original post by LangecrewI have to program this on my own now, and I've been given a whole list of parametric equations: Sphere, Ellipsoid, Cylinder, Double Sheet Elliptic Hyperboloid, etc...
Is this a homework assignment? I ask because this forum has a fairly strict 'no homework' policy. If it's not though, we'll be glad to help :)

Meanwhile, a search term that might be useful to you is 'mesh'; you should be able to find info online explaining how to generate meshes for some of the shapes you mention. Try googling 'sphere mesh', 'cylinder mesh', and so on and see what comes up.

##### Share on other sites
No, this is not a homework assignment. I've been out of school for too long. That's the whole problem, or else I might have been able to just write the function without help.

If you really must know, the company I work for has a small piece of software to analyze point clouds. We use it internally to test various things, it's not a product or anything. One of the things it does is: lets say you have a point cloud which describes a sphere but one point (or more) is way off, the software will project this bad point onto the surface of the actual shape that is defined by the rest of the points. It'll also give other stuff, number of bad points, sphere radius, a b and c for an ellipsoid, etc...We thought it would be nice to create a mesh of verticies artificially, so that we could use something like OpenGL to draw a ghosted sphere along with the data points. That way, you could very easily see the actual shape that any bad point would project to.

I know what you're thinking. Projecting a bad point onto a calculated shape is pretty heavy math, especially for things like ellipsoids and more complex shapes. I should just ask the guy that wrote all this stuff, right? Well, I sort-of can't. He's tied up with the development of this heavy math...from what I understand he's a very busy guy working overseas right now. I'd really rather try to solve this on my own before I bother him :-)

[Edited by - Langecrew on January 31, 2007 8:47:18 AM]

##### Share on other sites
The Slices/levels approach wont give you uniform distribution.
Try to "Catmull-Clark subdivision".

Or (if you have the equation like x/y+z-20=0) you can do the lazy way:

Make an array of random points
For every point:
calculate the equation
if not 0, move the point a bit, so the equation gives you something closer to 0
repeat many times, so you get a nice approximation

The points should converge to the "equation equals to 0" surface. If the calculation is not complex.

[Edited by - Gagyi on January 31, 2007 9:07:06 AM]

##### Share on other sites
OK, I've almost got it. It's doing the right number of slices per ring, it's not doing the correct number of rings. The code that I've gotten so far will give me 8 slices and 5 levels, if I call it with 8 and 8. Can anyone help me figure out how to tweak the following code so that it actually creates a sphere with 8 rings with 8 points each; keeping in mind that the first and last ring should just be single points? (forgive the Delphi code)

////////////////////////////////////////////////////////////////////////////this code is automatically called when the application window is created//////////////////////////////////////////////////////////////////////////procedure TForm1.FormCreate(Sender: TObject);begin  //try to create a sphere of radius 5, with 8 levels and slices  CreateSphereList(5, 8, 8);end;///////////////////////////////////////create the list of sphere verticies/////////////////////////////////////procedure TForm1.CreateSphereList(Radius: integer; Levels, Slices: integer);var  i, j, Count: integer;  SliceRad, LevelRad: double;  Re, Ye: double;begin  //radians covered by each slice or level  SliceRad:= (Pi * 2) / Slices;  LevelRad := (Pi * 2) / Levels;  SetLength(Xs, Slices * Levels);  SetLength(Ys, Slices * Levels);  SetLength(Zs, Slices * Levels);  Count := 0;  //going level by level  for i := 0 to Levels - 1 do  begin    //get the radius and the y value for this level    Re := Radius * Cos(LevelRad * i);    Ye := Radius * Sin(LevelRad * i);    //iterate around the level to place points at each slice    for j := 0 to Slices - 1 do    begin      //get the XYZ of this point      Zs[Count] := Re * Sin(SliceRad* j) * (-1);      Xs[Count] := Re * Cos(SliceRad* j);      Ys[Count] := Ye;      Inc(Count);    end;  end;  //print all the points on the screen  for i := 0 to Count - 1 do  begin    Memo.Lines.Add(FloatToStr(Xs) + #9 + FloatToStr(Ys) + #9 + FloatToStr(Zs));  end;end;

I'm to the point where I'm just swapping random variables...basically just guessing to get the right combination of code. I hate to be "that guy," but "What's wrong with my code?"

##### Share on other sites
I've already gotten the code to work, there are just a couple bugs that I can't get rid of because, once again, I just don't know the math.

the following code will still produce the incorrect number of levels. If I call it with the arguments below, the sphere will have 5 levels, instead of 4. Also, there will be a point that is in the resulting data set twice. I've tried to change lots of different things about the code, but the only result I get is that the sphere points get drawn off in space somewhere. Can anyone PLEASE look over this and see what it is that I'm doing wrong?

procedure TForm1.FormCreate(Sender: TObject);begin  CreateSphereList(100, 4, 4);end;procedure TForm1.CreateSphereList(Radius: integer; Levels, Slices: integer);var  i, j, Count: integer;  SliceRad, LevelRad: double;  Re, Ye: double;begin  SliceRad := (2 * Pi) / Slices;  LevelRad := (Pi) / (Levels);  SetLength(Xs, (Slices * Levels));  SetLength(Ys, (Slices * Levels));  SetLength(Zs, (Slices * Levels));    Count := 0;  for i := 0 to Levels do  begin    Re := Radius * Sin(i * LevelRad);    Ye := Radius * Cos(i * LevelRad);    for j := 0 to Slices - 1 do    begin      Xs[Count] := Re * Sin(j * SliceRad);      Ys[Count] := Ye;      Zs[Count] := Re * Cos(j * SliceRad);      Inc(Count);    end;  end;  for i := 0 to Count do  begin    Memo.Lines.Add(FormatFloat(FormatString, Xs) + #9 +      FormatFloat(FormatString, Ys) + #9 + FormatFloat(FormatString, Zs))  end;  Memo.SelectAll;end;

1. 1
2. 2
Rutin
20
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633738
• Total Posts
3013617
×