# Thread: How to draw implicit surface?

1. ## How to draw implicit surface?

I would like to plot a surface defined by an implicit equation, i.e. f(x,y,z) = ax+by+cz-d

May I know how can I draw it? I would be grateful if you could tell me the algorithm.

2. ## Re: How to draw implicit surface?

This is how I would do it:
1) Solve the equation for z by assuming f(x,y,z)=0;
2) Write 2 for loops:
Code :
```   for (double x=<x_start>; x<=<x_end>; x+=<evaluation_step>)
{
// This doesn't have to be a line strip, so you can make it
// anything that makes more sense to you - I just used line strip for simplicity.
glBegin(GL_LINE_STRIP);
for (double y=<y_start>; y<=<y_end>; y+=<evaluation_step>)
{
double z=f(x,y); // z=(d-ax-by)/c;
glVertex3f(x,y,z);
}
glEnd();
}```

3. ## Re: How to draw implicit surface?

Thank you for the suggestion. However, I will need to perform trial and error on <x_start> and <x_end>.

Is there another method? I plan to generate arbitrary surfaces, which I do not know beforehand (so I can't really have time for trial and error testing).

4. ## Re: How to draw implicit surface?

Let's say you have the implicit surface f(x,y,z) = n, where n is some iso-value. The points in space where f(x,y,z) evaluates to n lie on the implicit surface. A reasonable, and popular, way of rendering such a surface is to sample the function on a grid and, thereafter, extracting triangles using the Marching Cubes algorithm. You will find lots of material available online on this topic.

The grid sampling is done by constructing a voxel grid, and evaluating the function at the corners of each voxel. It is possible to determine if the voxel contains one or more parts of the surface by checking its 8 corners. More details, as mentioned, available online.

T

5. ## Re: How to draw implicit surface?

Thanks for the info. Sorry, I'm a complete newbie. Can someone give me the C++ code, which does the plotting the implicit surface for me?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•