View Full Version : How to draw implicit surface?

booncw

11-16-2009, 04:31 AM

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.

igorgiv

11-16-2009, 05:17 PM

This is how I would do it:

1) Solve the equation for z by assuming f(x,y,z)=0;

So in your case: z=(d-ax-by)/c;

2) Write 2 for loops:

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();

}

booncw

11-17-2009, 12:48 AM

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).

thinks

11-17-2009, 02:41 AM

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

booncw

11-18-2009, 07:00 AM

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?

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.