Click here to Skip to main content
15,442,578 members
Articles / Programming Languages / C#
Posted 21 Feb 2007


133 bookmarked

Plot 3D surfaces

Rate me:
Please Sign up or sign in to vote.
4.86/5 (54 votes)
21 Feb 20072 min read
Simply render a 3D surface on your screen without OpenGL/DirectX.
Screenshot - Plot3D_sample1.png


This article describes a simple method of rendering 3D surfaces on a 2D plane. It doesn't use OpenGL or DirectX or stuff like that. It just utilizes the power of the CPU. Simplicity has, of course, its price - the rendering process isn't as fast as when using hardware acceleration.

Its application varies from simply admiring beautiful 3D surfaces to data visualization purposes, to stuff whatever one needs. I've used it in programs written for courses of Optimization Methods, Identification, Calculus (Mathematical Analysis), and Dimensional Analysis.


  • Density - Size of the spanning mesh.
  • PenColor - Color of the drawing pen. Used to draw meshes.
  • StartPoint - Plotting start point.
  • EndPoint - Plotting end point.
  • Function - Function used to calculate surface vertices.
  • ColorSchema - Color schema assigned to mesh.


  • ReCalculateTransformationsCoeficients - Recalculates transformations' coefficients on the basis of new parameters.
  • Project - Performs projection. Calculates screen coordinates for the 3D point.
  • RenderSurface - Main method. Render the surface on given graphics.

Points of Interest

Additional classes ColorSchema and CompiledFunction are interesting parts of the code. The first one encapsulates an array of Color entries. It has some predefined color palettes. The other one compiles a given formula to a function delegate, providing simple parser services.


Surface3DRenderer sr = new Surface3DRenderer(70, 35, 40, 
                       0, 0, ClientRectangle.Width, 
                       ClientRectangle.Height, 0.5, 0, 0);
//new hue-based palette
sr.ColorSchema = new ColorSchema(120);
//enter your function here        

Use this to actually render something:


And this, whenever plotting area size changes:

sr.ReCalculateTransformationsCoeficients(70, 35, 40, 0, 0, 
     ClientRectangle.Width, ClientRectangle.Height, 0.5, 0, 0);



  • 22.02.2007 - first version.
  • 23.02.2007 - sample images added.

Sample (application)

Below, I'm publishing screenshots from an application that was written for my academic course of Optimization Methods (finding the minimum/maximum of functions). Labels are in Polish, but I hope that they are self-explaining.

Screenshot - wykres.png

Entering the formula:

Screenshot - wzor.png

Finding functions' minimum using the Greatest Slope method:

Screenshot - tabelka.png


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Written By
Architect Nokia Siemens Networks
Poland Poland
Michał is C# and whole .NET enthusiast. He graduated from computer science MSc studies at Wroclaw University of Technology, Poland.

He is interested in photography and diving. He is member of PADI, currently with divemaster certificate.

His favorite movies are Matrix, Amélie(Le Fabuleux Destin d'Amélie Poulain), Stargate SG-1 TV Serie and comedies of Mel Brooks.

Michał lives in Wroclaw, Poland. To contact Michał, email him at michal.brylka[mail-'"at'"-sign]

Comments and Discussions

NewsThis project is obsolete since today: A completely rewritten code is available now. Pin
Elmue4-Feb-21 7:15
MemberElmue4-Feb-21 7:15 
QuestionWould you have VB.Net (VB2008) Pin
Member 837876926-Jun-15 0:01
MemberMember 837876926-Jun-15 0:01 
Question3D Radio Wave Plot in space Pin
Member 232111821-Jan-15 9:44
MemberMember 232111821-Jan-15 9:44 
Question3D line plot? Pin
Lord of Scripts13-Dec-14 9:13
MemberLord of Scripts13-Dec-14 9:13 
Generalnice, may be just what i'm after.. Pin
ibyk301-May-13 6:43
Memberibyk301-May-13 6:43 
SuggestionRe: nice, may be just what i'm after.. Pin
ibyk303-May-13 4:57
Memberibyk303-May-13 4:57 
AnswerRe: Too many issues and bugs Pin
Elmue4-Feb-21 6:54
MemberElmue4-Feb-21 6:54 
GeneralMy vote of 5 Pin
ibyk301-May-13 6:28
Memberibyk301-May-13 6:28 
GeneralMy vote of 5 Pin
victorbos4-Apr-13 14:18
Membervictorbos4-Apr-13 14:18 
Nice clean working code. Superb
QuestionHow to achieve same grid effect as on second screenshot Pin
apaka31-Oct-12 22:14
Memberapaka31-Oct-12 22:14 
Questionsr is null before initialization in mono Pin
j1s1e129-Oct-12 17:55
Memberj1s1e129-Oct-12 17:55 
QuestionAdding mouse interaction Pin
xfx27-Mar-12 20:06
Memberxfx27-Mar-12 20:06 
SuggestionRe: Adding mouse interaction Pin
Michal Brylka5-Apr-12 1:27
MemberMichal Brylka5-Apr-12 1:27 
AnswerRe: Adding mouse support Pin
Elmue4-Feb-21 6:51
MemberElmue4-Feb-21 6:51 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 21:50
professionalManoj Kumar Choubey26-Feb-12 21:50 
QuestionWhile obsX smaller than 0 Pin
transparency5-Apr-11 23:13
Membertransparency5-Apr-11 23:13 
AnswerRe: Drawing artifacts Pin
Elmue4-Feb-21 6:47
MemberElmue4-Feb-21 6:47 
Generaluser interaction Pin
now7864-Apr-11 11:09
Membernow7864-Apr-11 11:09 
GeneralExcellent library; license question Pin
sirkne12322-Sep-09 8:35
Membersirkne12322-Sep-09 8:35 
GeneralI can,t calculate the beginings coordinates of 3d plot Pin
artem0055-Apr-09 20:36
Memberartem0055-Apr-09 20:36 
GeneralRe: I can,t calculate the beginings coordinates of 3d plot Pin
Michal Brylka2-Sep-09 9:14
MemberMichal Brylka2-Sep-09 9:14 
GeneralRe: I can,t calculate the beginings coordinates of 3d plot Pin
artem0053-Sep-09 4:51
Memberartem0053-Sep-09 4:51 
GeneralTransformations Pin
Linuxman14-Jan-09 2:15
MemberLinuxman14-Jan-09 2:15 
AnswerRe: Rotation angle instead of observer coordinates Pin
Elmue4-Feb-21 6:43
MemberElmue4-Feb-21 6:43 
QuestionQuestion about 3D graphic Pin
johndoelee1-Apr-08 5:30
Memberjohndoelee1-Apr-08 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.